Tips

Iphone Safari back button cache problem

April 12, 2012 by admin 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 Asterisk, Symfony, Cake , Code-Igniter, Jquery , XAMPP, XHTML, AJAX, MySql, Seo, Web Design, Wordpress, iPhone development.

Today’s Tips
  • Eclipse crashes while you export apk in mac – Solution
  • Hide Icons in Mac Desktop
  • Adb Logcat command to search by tag name – Android App
  • Linux command to show the size of the folders
  • Remove all SVN folders recursively from a project folder in Mac
  • Clear Fabook share cache – Facebook development
  • Twitter json Api Url changed
  • Get operator ID( MNC+MCC) from SIM Card – Android App
  • Get device brand name – Android App
My Facebook