'pageshow' is not received when pressing "back" button on Safari on *IPad"
javascript, jquery, mobile-safari, safari
Solution
You can check the `persisted` property of the `pageshow` event. It is set to false on initial page load. When page is loaded from cache it is set to true.
window.onpageshow = function(event) {
if (event.persisted) {
alert("back to page");
}
};
For some reason jQuery does not have this property in the event. You can find it from original event though.
$(window).bind("pageshow", function(event) {
if (event.originalEvent.persisted) {
alert("back to page");
}
};
Problem
I have the following handler: ``` $(window).bind('pageshow', function() { alert("back to page"); }); ``` When I navigate away from the page (by pressing on a link) and return back to the page (by pressing the "back" button), the alert() is not called (IPad 2, iOS 5.1). What am I doing wrong please? Any other event I need to bind to? PS: interesting that pagehide is received properly when navigating away from the page.