找出用户在浏览器历史记录中的位置 [英] Find out where in browser history the user is

查看:156
本文介绍了找出用户在浏览器历史记录中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我使用 history 对象访问浏览器历史记录,具体来说,我可以使用 history.back(); history.forward(); history.go(item-number)(或 history.go(URL))。我试图确定用户当前在浏览器历史记录中的位置。

I know I access browser history using history object, specifically, I can use history.back();, history.forward(); and history.go(item-number) (or history.go(url)). What I am trying to determine where in the browser history the user currently is.

例如,Firefox可能支持从历史记录中访问个别网址,但这不是我的意思之后,因为20个网址的历史可能包含重复的网址。

Firefox, for example, may support accessing individual url's from the history, but that's not what I'm after, because the history of 20 url's may contain repeated url's.

请注意,我对项目中的历史不感兴趣 - 而是任何用户的浏览器历史记录会话。

Note that I am not interested in a history within my project - but rather browser history within any user's session.

例如,用户打开浏览器并浏览了20页 - 因此历史记录包含20个对象。然后用户按下后退按钮4次 - 最后是20页中的第16页(或者说是0..19页中的第15页)。有没有办法使用JavaScript获得当前的偏移量(16或15)?如果是,那么如何?

For example, a user opened the browser and went through 20 pages - so the history contains 20 objects. Then the user hit back button 4 times - and ended up on the 16th of the 20 pages (or rather 15th of the 0..19 pages). Is there any way to get this current offset (16 or 15) using JavaScript? If yes, then how?

推荐答案

history.length

返回当前历史记录的长度。

returns the length of the current history.

遗憾的是没有方法来确定你的位置。

sadly there is no method to figure out where in it you are.

这篇关于找出用户在浏览器历史记录中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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