当按下按钮时,防止浏览器捕捉到上一个滚动位置 [英] Prevent browser from snapping to previous scroll position when pushing back button

查看:134
本文介绍了当按下按钮时,防止浏览器捕捉到上一个滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < p>< p>< p> a href =javascript:history.go(-1)
onClick =javascript:history.go(-1)title =< GO BACK>< / a>

按下该按钮后,浏览器将返回此页面上的上一个滚动位置
i want停止该行为并加载页面顶部。



希望有人知道一个合适的解决方案。



-exemple -



打开一个页面向下滚动到一个新页面并点击返回按钮页面将自动滚动到您之前滚动的位置!

解决方案

我相当肯定你描述的行为最好被归类为被认为是用户偏好的东西之一。 (你不打算篡改的其中一件事)

@mrtsherman想出了一个黑客/办法解决这个,但除非它严重破坏了你的web应用的可用性,我想你应该让浏览器表现为用户通常期望它的行为(和滚动到他们的位置在他们离开页面时)。如果你使用它的话,一定要把他的甜蜜的金块拿给mrtsherman。


I need to prevent browser from snapping to previous scroll position when the user pushed a back button like this:

<a href="javascript:history.go(-1)"
      onClick="javascript:history.go(-1)" title="< GO BACK"></a>

after pushing that button the browser will return to the previous scroll position on this page i want to stop that behavior and just load the top of the page.

Hope someone know a proper solution.

-exemple-

open a page scroll down go to a new page and hit the back button the page will auto scroll down to the place you scrolled before!

解决方案

I'm fairly certain the behavior you're describing is is best classified as one of those things considered to be a user preference. (One of those things that you're not meant to tamper with)

@mrtsherman came up with a hack/workaround for this, but unless it's seriously breaking your webapp's usability, I think you should let the browser behave as the user would normally expect it to behave (and scroll to the position they were in when they left the page). Be sure to upvote mrtsherman for his sweet nugget of js if you use it.

这篇关于当按下按钮时,防止浏览器捕捉到上一个滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆