在 IE 中获取页面引用的最可靠方法是什么?
在浏览器扩展 (BHO) 中,我想知道将用户引向当前页面的 URL。我以为我可以获取 document.referrer,但我发现如果在新窗口中打开链接,它是空白的。这只是强硬的摩托车手还是我可以在某些情况下使用 opener.location.href 或其他什么?
作为后续工作,我目前在页面加载时(即在 DocumentComplete 上)获取此信息,但我更愿意在 BeforeNavigate2 上获取它。除了在 BeforeNavigate2 上使用当前位置作为引荐来源网址之外,我看不到任何方法可以做到这一点,但是如果用户在地址栏中输入新的 URL,这会将当前页面作为引荐来源网址。即,看起来他们从站点 A 上的链接导航到站点 B,实际上他们去了站点 A,然后输入了站点 B 的 url。
更新: 据我所知,有时会设置“opener”属性(如果窗口是从 javascript 打开的?),因此我们可以从中获取有效的引用页面。有谁知道具体什么情况下可以使用这个功能吗?
From within a browser extension (BHO) I want to know the URL that referred a user to the current page. I thought I could just get the document.referrer, but I find that's blank if links are opened in a new window. Is this just tough bikkies or can I use opener.location.href in some cases, or something else?
As a follow-up, I'm currently getting this when the page has loaded, ie on DocumentComplete, but I'd prefer to get it on BeforeNavigate2. I don't see any way to do that except use the current location as the referrer on BeforeNavigate2, however that will give me the current page as a referrer if users enter a new URL in the address bar. ie it'll look like they navigated from a link on site A to site B where actually they went to site A then typed in the url for site B.
UPDATE:
From what I can tell, sometimes the 'opener' property will be set (if the window has been opened from javascript?) and therefore we can get the effective referrer page from that. Anyone know specifically in which situations this is available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
获取此信息的唯一方法是从 HTTP 引荐来源,因此不幸的是,您可能无法使用对于该标头值为空的任何情况,祝你好运。
The only way to get this information is from the HTTP referrer, so unfortunately you may be out of luck for any situations in which that header value is blank.
除非您拥有包含指向新窗口的链接的页面,并添加哈希或 ID 或标识会话或链接的内容,否则您将无法捕获引荐来源网址。
Unless you owned the page that has the link to a new window, and add a hash or id or something identifying to a session or to the link, you will not be able to capture the referrer.