Event on iphone page only fires once

I am trying to use the pageshow event for safari (iphone) to fix some problems with back button cache. But it seems to work only once when using the back button.

I have this handler on page A :

 window.addEventListener("pageshow", function () { alert("pageshow"); }); 

Then go to page B and go back to A - everything works fine. But when I go back to page B and go back to A again, then nothing will happen.

Example: go to this script: https://jsfiddle.net/y278q8q0/ , then go to any other page and play using the "Back" and "Forward" buttons. The event will fire only once.

The way it looks on iphone 6 with ios 8.4: https://vid.me/5WPe

change

Question

was marked as a duplicate of this: 'pagehow' was not received when clicking back on Safari * iPad "

It is difficult to say whether these problems have the same cause. In my case, the event always fires once at the beginning. I also tried to implement all non-jquery solutions from the question mentioned, and none of them work for me.

+6
source share
1 answer

Probably the same problem has been resolved in a post since 2012 .

So your code should be:

 window.addEventListener("pageshow", function () { if (event.persisted) { alert("pageshow"); } }); 

I do not have access to the safari right now, so I can not check it. Please answer if this is correct.

-2
source

All Articles