Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent cached iPhone webapp from reloading (scrolling to top)

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).

like image 397
Alec Jacobson Avatar asked Jul 19 '10 18:07

Alec Jacobson


3 Answers

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.

like image 69
Glenn Maynard Avatar answered Oct 18 '22 20:10

Glenn Maynard


What I'm struggling with here is that the app actually seems to stay "in memory" longer if I use regular Safari as opposed to running in "apple-mobile-web-app-capable" mode. In the later case something as simple as pressing the home button, then task-switching back to the app causes a reload. Doing the same thing just in Safari often does not reload. So I'm worse off by using "apple-mobile-web-app-capable".

like image 28
James Koch Avatar answered Oct 18 '22 21:10

James Koch


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)

like image 36
JakeCigar Avatar answered Oct 18 '22 20:10

JakeCigar