admin管理员组文章数量:1414908
When I access the JavaScript variable window.history.length
I am returned the size of my window history. As I navigate forward from one page to another and then on to another, the length of window.history
increases. As I go back through my history using the browser back button, the value of window.history
does not decrease even though I am moving back through the history. Why is this?
When I access the JavaScript variable window.history.length
I am returned the size of my window history. As I navigate forward from one page to another and then on to another, the length of window.history
increases. As I go back through my history using the browser back button, the value of window.history
does not decrease even though I am moving back through the history. Why is this?
- 1 It can decrease if you navigate back a few pages and then visit a different page than you've gone before. Click around a few times on StackOverflow, then check the length. Go back a few pages and check the length again, it should be the same. Click a different length and it will be smaller. – Cory Danielson Commented Nov 3, 2014 at 4:01
1 Answer
Reset to default 7Think of window.history
as a logically growing list or array of pages visited. Initially, there is only the initial page. When you navigate forward, a new entry is added to the end of the list and window.history.length
increases by one. When you go back a page, the list does not have the entry you were previously at removed. Instead, it remains and you then have the opportunity to go forward (back to the page you just came back from).
What this means is that you shouldn't use the length of window.history
as an indicator of how far you are from the start of your browsing session. For example, if your window.history.length
has a value of 5 that does not mean that if you go back 3 pages you will be at the 2nd page you visited. window.history.length
represents the length of the number of pages you have visited in a forward direction but says nothing about where you currently are within that list.
If after navigating backwards, you visit a forward page that is not the same as the previous one in the forward chain, the list will be changed and so will the length as you are now no longer able to forward visit the entries that you had previously returned from.
本文标签: javascriptWhy does the size of my windowhistory not decreaseStack Overflow
版权声明:本文标题:javascript - Why does the size of my window.history not decrease? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745175751a2646230.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论