iphone - working - webkit-overflow-scrolling alternative




Prevent cached iPhone webapp from reloading(scrolling to top) (3)

I have an iPhone webapp that uses a cache manifest to work offline. I add the webapp to my home screen, use it (say scroll to a certain location on a page), then go back to homescreen. When I open the app again, for a brief moment I see where I used to be (at that scrolled location on that page), but then the app "reloads" and I get scrolled to the top of the mainpage. Is there a way to prevent this "reloading"? This happens even in airplane mode (ie everything is working off the cache).


// on load

window.scroll(0,0);

To ensure no old content is displayed while launching I use this in my page:

window.addEventListener('unload', function() { $('body').hide(); } );

Thus the last state of the page is empty and is what is shown to the user when the page is opened again.


I don't believe there is a real 'reload' event. onload and onunload are all we get.

the onload handler starts up as if it is your first time coming to the page.

the onunload handler is the key to clearing out old content.

I like to provide alternate content for people who are coming back to my web app.

window.onunload=function(){
  document.getElementsByTagName('body')[0].className+=' unloading'
}

And let the CSS do the dirty work to hide most of the body and show alternate content.

(this answer does not rely on jQuery or other frameworks)


You're just seeing the default startup image, which is just a screenshot of the last place you were at. It's not "reloading"; the app wasn't loaded to begin with.

Search for "apple-touch-startup-image" to set a real loading image.







reload