0

My project is a one-pager using simple css and js, gsap for timelines and animation.

I tested reloading my website with a button 'onclick' with window.location.reload(). Works fine!

If user swipes in browsers history, I tried:

window.addEventListener('pageshow', function (e) {
    if(e.persisted) {
        window.location.reload();
    }

On desktop it works. On Android it works. But on IOS mobile pure chaos. It seems that scripts are loaded several times, the performance is slow, all browsers,...

How can I reload the whole website on mobile after using browser history navigation?

br chris

1 Answers1

0

Because pageshow run after load, so, you can:

window.addEventListener('pagehide', function(e) {
    var $body = $(document.body);
    $body.children().remove();
    // after callback, run this script
    setTimeout(function() {
        $body.append("<script type='text/javascript'>window.location.reload();<\/script>");
    });
});
jeremyjone
  • 183
  • 12