iPhone Safari loads the page from the cache when you use the back button to navigate back. I found some jquery functions are not working properly when it loads from cache. You can resolve this problem by reloading the page again but it is not a good solution. My problem was a little bit different, all other javascript was working fine except the ‘windows.scroll’ function, so I fixed that in the following way
At first I used below code
$(window).scroll(function(){ }); |
but the scroll function never been called when the page loads from the cache in iphone. So I rewrote the above code in the following way.
window.onscroll = scrollingWindow; function scrollingWindow() { } |
Then on the page show event reloaded the javascript file where I wrote the above code again.
<body onpageshow="reloadScript(event);" ></body> |
function reloadScript() { if( event.persisted && typeof reloadUrl == 'function' ) { $.getScript('common.js'); // Load the javascript file where I wrote the scroll function. } } |
If you want to reload page, the reload function can be written as follows.
function reload() { if( event.persisted && typeof reloadUrl == 'function' ) { location.reaload(); } } |
If anyone has a better idea please post as comments.
Tagged iphone back button, iphone back button not working, iphone back button problem, iphone cache
kakakishApr 23, 2012 at 12:25 pm
ThanQ…….
@raycohenMay 1, 2012 at 4:24 pm
try binding to ‘touchmove’ as well as scroll:
$(window).bind(‘scroll touchmove’, …
For me this gets things working when I return to a page using the back button.