简体   繁体   English

Javascript-单击后退按钮时,将页面滚动到上一页的最后位置

[英]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.

相关问题 移动设备上的 Safari 浏览器后退按钮,不会将用户返回到上一页的最后滚动位置 - Safari browser back button on mobile, doesn't return user to last scroll position on previous page 单击返回按钮时如何记住上一页的滚动 position - how to remember previous page's scroll position when click back button 返回上一页时无限滚动中的jQuery滚动位置历史记录 - jQuery scroll position history in infinite scroll when go back to previous page 如何返回上一页并在动画后恢复滚动位置? - How to go back to the previous page and restore the scroll position after an animation? html/js: 在相同的滚动位置返回上一页 - html/js: go back to previous page in the same scroll position JQuery:返回上一页时如何返回完全相同的滚动位置 - JQuery: How to return to the exact same scroll position when going back to previous page JavaScript后退按钮无法正常工作-滚动到页面底部,而不是先前的滚动位置 - Javascript back button not working properly -scrolling to the bottom of the page, instead of previous scroll location Javascript页面滚动位置 - Javascript Page Scroll Position 浏览器后退按钮命中时重定向到错误页面? - Redirect to error page when the browser back button hit? 当按下浏览器后退按钮(在 Javascript 中)时,如何将特定变量传递给 go 返回上一页? - How to pass a specific variable to go back to the previous page when the browser back button is pressed (In Javascript)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM