PhilS PhilS - 2 months ago 14
iOS Question

PhoneGap / Cordova "click" working in browser, but not working on Developer App?

I have managed to create a login/signup screen, which works perfectly when served by PhoneGap and viewed in a browser.

However when tested on an iPhone using the PhoneGap App, the "click" function no longer works.

var myApp = new Framework7();
var $$ = Dom7;

// Handle Cordova Device Ready Event
$$(document).on('deviceready', function() {

//wait for signup page to be fully loaded
myApp.onPageInit('signup', function (page) {

//event listener for signup button
var signupButton = document.getElementById("signup");

if(signupButton) {
signupButton.addEventListener("click", signup, false);
}

//on click of signup button
function signup() {

login code here
}
});
});


I am using this "addEventListener" method instead of:

$("#signup").on("touchend", function (){signup()});
$("#signup").on("click", function (){signup()});


After they also did not work on mobile, and stumbling across this question in an attempt to find a solution:

cordova/phonegap onclick doesn't work

Do these methods / handlers behave differently in a browser vs on the PhoneGap app?

Answer Source

I had the same issue on iOS and had to add e.preventDefault() to resolve the issue.

$('#signup').on('click', function (e) {
    e.preventDefault();
    signup();
});