Tips

Iphone Safari back button cache problem

April 12, 2012 by Sarath DR in Tips, Web Development with 2 Comments

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 , , ,

Share this to

2 Comments

  1. kakakishApr 23, 2012 at 12:25 pmReply

    ThanQ…….

  2. @raycohenMay 1, 2012 at 4:24 pmReply

    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.

Leave a reply

Your email address will not be published. Required fields are marked *

*

About
View Sarath D R's profile on LinkedIn

I am a technology consultant and an entrepreneur focused on the following technologies Java,Spring, Android, Angular, Asterisk, Symfony, Cake , Code-Igniter, Jquery , XAMPP, XHTML, AJAX, MySql, Seo, Web Design, Wordpress, iPhone development.

Today’s Tips
  • Generate Codova.jar file from Phonegap project using ant
  • Google map javascript client  to find the geographic co-ordinates  from  Address or post code
  • Update Android main UI from Webview – Phonegap Plugin
  • Jplayer is not working  with HTC One Android 4.3 version browser
  • Regular expression to validate mobile phone numbers starting with + ( plus ) – php
  • Simple pagination script for PHP
  • Useful adb ( Android Debug Bridge ) commands
  • Change the javascript files url to absolute url – Symfony 1.4
  • Set Http authentication header from Client – PHP / CURL

This site uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.This site also uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies.

Close