且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JavaScript中获取以前的URL?

更新时间:2023-02-21 15:20:48

document.referrer

在很多情况下会得到你的网址用户访问的最后一页,如果他们通过点击链接到达当前页面(而不是直接键入地址栏,或者我相信在某些情况下,通过提交表单?)。由 DOM Level 2 指定。 此处了解更多信息。

in many cases will get you the URL of the last page the user visited, if they got to the current page by clicking a link (versus typing directly into the address bar, or I believe in some cases, by submitting a form?). Specified by DOM Level 2. More here.

window.history 允许导航,但出于安全和隐私原因,不允许访问会话中的URL。如果有更详细的URL历史记录,那么您访问的每个站点都可以看到您去过的所有其他站点。

window.history allows navigation, but not access to URLs in the session for security and privacy reasons. If more detailed URL history was available, then every site you visit could see all the other sites you'd been to.

如果你正在处理在你自己的网站上移动的状态,那么它可能不那么脆弱,当然使用正常的会话管理技术之一更有用:cookie数据, URL参数或服务器端会话信息。

If you're dealing with state moving around your own site, then it's possibly less fragile and certainly more useful to use one of the normal session management techniques: cookie data, URL params, or server side session info.