[英]How can I check to see if a forward history exists in Javascript? (Disabling back button)
Got a window.history.go(1)
to stop the user hitting the back button, but was wondering if I could check to see if a forward history exists before doing it, so I can display a popup warning the user not to press the back button. 有一个window.history.go(1)
来阻止用户按下后退按钮,但是想知道我是否可以检查是否存在前进历史记录,所以我可以显示弹出警告用户不要按返回键。
I know you can get the history length, but is there a way to get the current position in the history list? 我知道你可以获得历史长度,但有没有办法在历史列表中获得当前位置? Or some other way of doing this... 或者其他一些方法......
AFAIK you won't be able to access the history from JavaScript. AFAIK您将无法从JavaScript访问历史记录。 It will be a security hole and most of the browsers won't allow that. 这将是一个安全漏洞,大多数浏览器都不允许这样做。 Probably there might be a workaround in IE by using ActiveX. 可能在IE中可能有使用ActiveX的解决方法。
Found this entry which might be useful to you 找到此条目可能对您有用
window.history 的window.history
There is a next property. 有一个下一个属性。
Returns the URL of the next item in the session history This property is not available to web content and is not supported by other browsers. 返回会话历史记录中下一个项目的URL此属性不可用于Web内容,其他浏览器不支持此属性。
For security reasons the History object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history. 出于安全原因,History对象不允许非特权代码访问会话历史记录中其他页面的URL,但它允许它导航会话历史记录。
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. 无法清除会话历史记录或禁用非特权代码的后退/前进导航。 The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL. 最接近的可用解决方案是location.replace()方法,该方法用提供的URL替换会话历史记录的当前项。
Don't break the back (or forward) button. 不要打破后退(或前进)按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.