访问窗口历史对象中的 URL

发布于 2024-09-08 23:01:31 字数 431 浏览 6 评论 0原文

有没有办法在 Safari 中随机访问 Javascript 的 History 对象中的 URL?我正在编写一个扩展,我需要在特定格式的页面请求中捕获上一页的 URL。据我所知,History 对象定义在浏览器中是非标准的。 Safari 似乎只公开其 length 属性和在历史记录中实际移动的标准方法。当其他实现公开 currentpreviousnext 属性时,我看不到任何内容告诉我 Safari 会做同样的事情。

我也尝试过 document.referrer,但在这种情况下似乎没有被填充。

我只需要在给定页面上显示以前访问过的 URL。还有其他方法可以访问该网址吗?

谢谢。

Is there any way to randomly access the URLs in Javascript's History object in Safari? I'm writing an extension where I need to, on a specifically-formatted page request, capture the URL of the previous page. From what I've been able to find, the History object definition is non-standard across browsers. Safari only seems to expose its length property and the standard methods that actually move within the history. Where other implementations expose current, previous and next properties, I can't see anything that tells me Safari does the same.

I've also tried document.referrer, but that doesn't appear to get populated in this case.

I just need to display the previously accessed URL on a given page. Is there any other way to access that URL?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耀眼的星火 2024-09-15 23:01:31

你不能真正做到这一点,至少不能以任何白帽方式做到这一点。通过设计。您可以让用户前后移动,但看不到 URL。

不那么严谨的编剧当然会将此视为一种挑战。我相信他们最接近的是动态地将一堆已知的比较链接写入页面,然后检查它们以查看它们是否以“已访问”颜色状态显示。也许,如果您在一个封闭且可预测的环境(内部网应用程序?)中工作,并且具有一组已知的 URL,那么这可能是您的有效方法。话又说回来,在这样的环境中,您可以通过会话管理在服务器端处理此问题。

You can't really do this, at least in any white-hat way. By design. You can step the user backward and forward, but you can't see the URLs.

Less scrupulous script-writers have of course taken this as a challenge. I believe the closest they've come is to dynamically write a bunch of known comparison links to the page, and then inspect them to see if they're showing in the "visited" color state. Perhaps if you're working in a closed and predictable environment (an intranet app?), with a known set of URLs, this might be a valid approach for you. Then again, in such an environment you could deal with this on the server side with session management.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文