[英]Javascript - Scroll page to last position of previous page when the back button is hit
I decide to make my own "neverending" scroll page which suits exactly my needs rather than making comfortable with some extensive classes that could not have to work exactly the way I would like them to. 我决定制作自己的“无休止”滚动页面,该页面完全适合我的需求,而不是让一些无法完全按照我希望的方式工作的广泛类适应。
Now, when all works like a charm, last thing remains. 现在,当所有事物都像魅力一样运转时,最后一件事仍然存在。 Preserve the scroll position when the browser's back button is hit.
按下浏览器的后退按钮时,保留滚动位置。 Every time you get to the bottom of the page I change the hash # part of the url.
每次您到达页面底部时,我都会更改网址的井号#部分。 When the back button is hit, it shows waiting icon and then loads dynamic content.
当单击后退按钮时,它将显示等待图标,然后加载动态内容。
Firefox scroll after that exactly to place the page was scrolled (good). Firefox在此之后完全滚动以滚动页面(良好)。
Opera and Safari seem to load exactly the same state there were before, so dynamic content seems to be already prefetched and displayed (good). Opera和Safari似乎加载了与以前完全相同的状态,因此动态内容似乎已经被预取并显示了(很好)。
But IE and Chrome want to scroll before dynamic content is load and they don't try again later. 但是IE和Chrome希望在加载动态内容之前进行滚动,因此以后不会再尝试。 IE get stucked at the top of the page and Chrome somewhere in the middle (bottom of the page before dynamic content shows up).
IE停留在页面顶部,Chrome停留在中间位置(动态内容显示之前页面的底部)。
Now, what could I do to solve this issue? 现在,我该怎么做才能解决这个问题? I could in theory store the current scroll position to url hash when any click is detected.
理论上,当检测到任何单击时,我可以将当前滚动位置存储到url哈希。 Then previous page is load and I could simply parse the hash and ScrollTop().
然后上一页已加载,我可以简单地解析哈希值和ScrollTop()。 But for some reason, this
但是由于某种原因
$(document).live("click", function() { window.alert("gotcha"); });
doesn't work for me anyway. 反正对我不起作用。
The document
doesn't have anything to be clicked on. 该
document
没有任何要单击的内容。 document.documentElement
is the root <html>
node, so attach events to that, or to the window
if appropriate. document.documentElement
是根<html>
节点,因此将事件附加到该节点,或者将事件附加到window
如果适用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.