我可以跟踪新窗口链接的引荐来源网址吗?
案例:
- 站点 A 包含一个在新窗口中打开站点 B 的链接。
- 站点 B 中的脚本正在尝试获取站点 A 的 url。
我的问题:有没有办法跟踪使用 target="_blank"
或 Javascript window.open()代码>函数?
如果是的话有什么办法可以完全隐藏推荐人吗?
Case:
- site A contains a link that opens site B in new window.
- The script in site B is trying to get the site A url.
My question: Is there any way to track the referrer of a new window which was opened using target="_blank"
or Javascript window.open()
function?
If yes then is there any way to completely hide the referrer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Referrer 位于 HTTP 标头中,因此无论窗口是空白窗口还是新窗口,它都可用。您可以通过以下方式获取 URL:
有些网站使用此方法来保护其网站免受点击劫持之类的影响,因此从链接页面隐藏引荐来源网址是不合适的。允许引荐来源欺骗的浏览器被认为是不安全的,一旦发现就会被修补。
更新
也许它并不像我想象的那样令人皱眉。 HTML5 有一个
属性,可以不发送 HTTP 标头中的引荐来源网址:
rel = "noreferrer"
。Referrer is in the HTTP header and so it will be available regardless of whether the window is blank or new. You can get the URL with:
There are sites that use this to protect their sites from things like click-jacks, so it would be inappropriate to hide the referrer from the linked page. Browsers that allow for referrer spoofing are considered unsafe, and it tends to be patched when found.
Update
Maybe it's not as frowned upon as I thought. HTML5 has a property for
<a>
to not send the referrer in the HTTP headers:rel = "noreferrer"
.IE 与 window.open 它失去了引用。简单地使用 jQuery 或不使用 jQuery 重写它:
IE with window.open it loses the referer. Simply use jQuery or re-write it without using jQuery:
如果您可以控制两个页面,请像这样打开窗口:
旁注:给窗口一个标题很重要,否则 IE 会自己拉屎。
在打开的窗口中,您将看到“opener”的引用:
If you have control of both pages open the window like so:
Side note: it's important to give the window a title or IE will poop itself.
In the opened window you'll have a reference to the "opener":
你检查过开启器位置了吗?如果我没记错的话,它对我有用。
Did you check opener location? It worked for me if I right remember.
最好的方法是:
我希望它有用
the best way is:
I hope it will be useful