更改引荐来源的值 [英] Changing the value of referrer

查看:129
本文介绍了更改引荐来源的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在Javascript中手动设置REFERER标头?

如何更改 document.referrer 的价值?

我试过这个

<body>
<center><a href="test.php" target="_self">self</a></center>
<script type="text/javascript">
    alert( document.referrer);
    document.referrer="test";
    alert( document.referrer);
</script>
</body>

它没有用,有什么想法吗?

It is not working, any ideas?

推荐答案

您无法直接修改引荐来源,但可以使用 history.pushState() / history.replaceState() 将新网址推送到浏览器历史记录中(提供您想要的网址) push具有相同的域名,然后当你离开时,新的URL将成为推荐人。

You can't modify the referrer directly, but you can use history.pushState() / history.replaceState() to push a new URL into the browser history (provided the URL you want to push has the same domain), then when you navigate away, the new URL will be the referrer.

请注意使用 pushState操纵历史记录添加了一个新的历史记录条目,但正在查看的页面保持不变,用户必须按两次浏览器的后退按钮才能返回一个实际页面。

Please note that manipulating the history using pushState adds a new history entry, but the page being viewed stays the same, and the user will have to press their browser's "Back" button twice to go back one actual page.

但是,如果您使用 replaceState ,请从页面y返回你想隐藏引用者将转到新设置的URL,因此请确保无论如何替换它都会将用户重定向回原始页面,而不是将它们发送到404或完全不同的页面。

However, if you use replaceState, coming back from the page you want to hide the referrer from will go to the newly set URL, so make sure that whatever you replace it with somehow redirects the user back to the original page instead of sending them to a 404 or a completely different page.

这篇关于更改引荐来源的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆