IPhone Web Application JavaScript events are interrupted after waking from sleep

I am trying to create a mobile safari / iphone web application using jQuery code that I already wrote for the desktop version of the application. The problem I ran into is that when my phone slept with a running web app, when I woke it up (slide failed), the JavaScript event handlers no longer function. In this case, when I click on the link that was used to update the AJAX through the onclick event, it actually follows the link, opening the page in a new Safari window, breaking the look of the native iPhone app.

The code that stops working:

$(function() {
var ajaxLoad;
var ajaxClick = function(e) {
    e.preventDefault();
    e.stopPropagation();
    $("body").load( $(this).attr("href"), ajaxLoad );
}
ajaxLoad = function() {
    $(this).find("a").click( ajaxClick );
}
$("a").bind( "click", ajaxClick );
});

      

When the code works, the result of the link will open in the frame of the web app, when it breaks, the code will open in a new Safari window, breaking the look of the actual app.

+2


source to share


1 answer


Not tested - but it helps to add "return false" to the end of the ajaxClick function to prevent the link from being activated.



0


source







All Articles