Javascript 我可以得到推荐人吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6856697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:29:28  来源:igfitidea点击:

Can I get the referrer?

javascriptasp.netuser-agentreferrer

提问by eugeneK

I have a website on which I dynamically create Javascript code using ASP.NET handler in which I should add the referrer to a database.

我有一个网站,在该网站上我使用 ASP.NET 处理程序动态创建 Javascript 代码,我应该将引用添加到数据库中。

I want to get referrer of referrer like so:

我想像这样获得推荐人的推荐人:

  • website1
  • website2(where I create pixel to another site)
  • website3(where pixel is located)
  • website1
  • website2(我在其中创建像素到另一个站点)
  • website3(像素所在的位置)

I don't have code access to website1, on website2I can only assign JavaScript.

我没有代码访问权限website1website2我只能分配 JavaScript。

If I get referrer in current application state I get website2.

如果我在当前应用程序状态下获得引用,我将获得website2.

Is there a way to get website1as referrer?

有没有办法获得website1推荐人?

回答by Tom

You can pass this value along: document.referrer.

您可以传递此值:document.referrer

That expression would need to be evaluated on website 2, not on website 3.

该表达式需要在网站 2 上进行评估,而不是在网站 3 上进行评估。

So:

所以:

// website2.html
<img src="website3.com/pxl.gif" id="pxl" />
<script>
document.getElementById('pxl').src += '?ref=' + encodeURIComponent(document.referrer);
</script>

The request to website3 will then include the referrer.

然后,对 website3 的请求将包含引用者。

回答by Daan Wilmer

It is impossible to get the referrer of website2 on website3 directly. However, since you can use javascript on website2, you could get the referrer (document.referrer) and add it to the url of the pixel you get. For example:

直接在website3上获取website2的referrer是不可能的。但是,由于您可以在 website2 上使用 javascript,您可以获取引用 ( document.referrer) 并将其添加到您获取的像素的 url 中。例如:

var referer = document.referrer;
var pixelUrl = 'http://website3/pixel?referrer=' + escape(referrer);
// create pixel...

Hope that helps

希望有帮助