简体   繁体   中英

HTML5 History API popstate reload safari refreshes page endlessly

I fonud safari refreshes the page endlessly when I hit the "back" button with this code

window.addEventListener('popstate', function() {
  location.reload();
});

Chrome and IE are fine. How can this issue be fixed?

Thanks

try to use

location.reload(true);

should work for Safari) MDN link

this hack is working for me :/

https://gist.github.com/voku/854fef3b9a3fbf10624f

 /** * reload on history-back with "history.pushState" usage * * Necessary hack because WebKit fires a popstate event on document load * https://code.google.com/p/chromium/issues/detail?id=63040 * https://bugs.webkit.org/process_bug.cgi */ $(window).bind('load', function() { if (Modernizr.history) { setTimeout(function() { $(window).bind('popstate', function() { location.reload(); }); }, 0); } }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM