我们可以使用 Javascript 获取浏览器历史记录吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11556781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:18:38  来源:igfitidea点击:

Can we get browser history by using Javascript?

javascriptbrowserbrowser-history

提问by Mayron

Can we get browser history for my site with Javascript ?

我们可以使用 Javascript 获取我网站的浏览器历史记录吗?

I can see some of old posts and threads talking about that... but those approaches didn't work for me.

我可以看到一些旧帖子和线程在谈论这个……但这些方法对我不起作用。

Is it possible or not and how?

可能与否以及如何?

回答by Pranay Rana

You can make use of History objectof javascript to do that

您可以利用javascript的History 对象来做到这一点

The history property has the return value as history object, which is an array of history items having details of the URL's visited from within that window. Also, note that the History object is a JavaScript object and not an HTML DOM object.

history 属性具有作为 history 对象的返回值,它是一个历史条目数组,其中包含从该窗口中访问过的 URL 的详细信息。另外,请注意 History 对象是一个 JavaScript 对象,而不是 HTML DOM 对象。

syntax of history property of Window Object:

Window 对象的 history 属性语法:

window.history 

回答by Riz

If you are looking a way to navigate in browser history URLs. These links would be helpful.

如果您正在寻找一种在浏览器历史 URL 中导航的方法。这些链接会很有帮助。

回答by Serdar

For privacy reasons, no it is not possible to read clients browser history data.

出于隐私原因,不能读取客户端浏览器历史数据。

If you are trying to observe or generate data about visitors for only on your domain, its possible to keep page information with sessions and cookies.

如果您试图仅在您的域上观察或生成有关访问者的数据,则可以使用会话和 cookie 保留页面信息。

you can also collect click data on your websites clickable objects by your own scripts which are sending the data by ajax requests.

您还可以通过自己的脚本收集网站可点击对象上的点击数据,这些脚本通过 ajax 请求发送数据。

if you are running a one page application type website and generating your own url's with "pushState()" function, you just need to add some extra code to collect that data and send the information with ajax on page/url changes.

如果您正在运行一个单页应用程序类型的网站并使用“pushState()”函数生成您自己的 url,您只需要添加一些额外的代码来收集该数据并在页面/url 更改时使用 ajax 发送信息。