javascript window.history.length 最大值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16355549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.history.length maximum value
提问by kml_ckr
Value of window.history.length
is very important in our project to detect backbutton is clicked on browser. However I realized that window.history.length
does not pass 50. How to solve this ? Thanks for your help.
值window.history.length
在我们的项目中非常重要,用于检测浏览器上的后退按钮是否被点击。但是我意识到window.history.length
没有通过50。如何解决这个问题?谢谢你的帮助。
采纳答案by Sedat Polat
回答by Alberto Zaccagni
Depending on whether you need it to be persistent across sessions and surviving a clean of the user information (cache, localStorage, etc...) you might want to adopt different solutions.
根据您是否需要它在会话中保持持久性以及是否需要清除用户信息(缓存、localStorage 等),您可能需要采用不同的解决方案。
One of the solutions could be to do something like this:
解决方案之一可能是执行以下操作:
window.onpopstate = function(event) {
var count = parseInt(localStorage.getItem('history-changes-count'), 10);
localStorage.setItem('history-changes-count', ++count);
};
Note that onpopstate
gets invoked only after a user action, it doesn't work if you modify the history programmatically.
请注意,onpopstate
仅在用户操作后才被调用,如果您以编程方式修改历史记录,则它不起作用。
More on the subject: https://developer.mozilla.org/en-US/docs/DOM/window.onpopstate
有关该主题的更多信息:https: //developer.mozilla.org/en-US/docs/DOM/window.onpopstate