Onpagehide event on iPad Safari

As there are some problems with onunload and onbeforeunload event on iPad Safari, I found an equivalent problem for iPad (pagehide) as stated in;

http://www.webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/

Now my question is: 1. Is the screen information equivalent for unloading or beforeunload events? 2. I use a DWR call (in simple terms, this is an AJAX call) inside this event handler of the current page as:

someObj.saveData(jsonString,{async:false}); 

Here saveData () is actually a Java function that saves data. Now, please, please ... I understand that this is a "FREE PRACTICE" for storing data on unloading events ... But this has been encoded in my application and I cannot change it ..

So my question is, how exactly will he behave ... how will he continue to work in the background while the page is unloading, and if the page is viewed at what point will it be called?

+4
source share
1 answer

beforeunload and unload start when the active page is destroyed, as it moves to the side or due to the browser closing.

pagehide starts when the active page is "paused", such as a drive.

If the browser is closed when the page is paused, it can never receive beforeunload or unload events.

pagehide was introduced because browser developers tried to pause and resume pages in the cache (instead of reloading them), but found that when they raised the unload event, many pages took destructive actions that would prevent them from resuming later. Therefore, they came up with pagehide as a similar but different alternative.

I understand that this is a “FREE PRACTICE” for storing data on unloading events

I am not sure about this ... Bad practice is to make synchronous requests for unload , because it will make the browser wait for a response when the user tries to close the window ... But I think that the request to send- asynchronously save and-forget will not be a problem.

So my question is, how exactly will he behave ... how will he continue to work in the background while the page is unloading, and if the page is viewed at what point will it be called?

Javascript code called from beforeunload or unload is usually the last piece of script that will run on your page until it is closed. That's why if you need a response from the server, a synchronous request is your only option (otherwise the answer will never be processed). At the end of the event, the page will be destroyed. The pagehide event pagehide similar, except that the page will not be destroyed, but instead it will be serialized and saved somewhere, so it can be loaded and continued later.

It follows that in the pagehide event you should not execute any cleanup logic such as destroying objects, etc.

More information can be found in this blog post from the WebKit team when they pagehide event: WebKit Page Cache II - unload event

+3
source

All Articles