简体   繁体   English

HTML5历史记录API popstate重新加载野生动物园不断刷新页面

[英]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. Chrome和IE都可以。 How can this issue be fixed? 如何解决此问题?

Thanks 谢谢

try to use 尝试使用

location.reload(true);

should work for Safari) MDN link 应该适用于Safari) MDN链接

this hack is working for me :/ 这个hack对我有用:/

https://gist.github.com/voku/854fef3b9a3fbf10624f 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); } }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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