访问窗口历史对象中的 URL
有没有办法在 Safari 中随机访问 Javascript 的 History
对象中的 URL?我正在编写一个扩展,我需要在特定格式的页面请求中捕获上一页的 URL。据我所知,History
对象定义在浏览器中是非标准的。 Safari 似乎只公开其 length
属性和在历史记录中实际移动的标准方法。当其他实现公开 current
、previous
和 next
属性时,我看不到任何内容告诉我 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能真正做到这一点,至少不能以任何白帽方式做到这一点。通过设计。您可以让用户前后移动,但看不到 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.