【问题标题】:document referrer location javascript remote php server文档引用位置 javascript 远程 php 服务器
【发布时间】:2011-05-28 13:18:29
【问题描述】:

我有以下代码在不支持 PHP 的网页中以 Javascript 模式获取引荐来源网址并将其传递给远程服务器:http://site.com/ref.php 其中$ref = $_GET['referrer']; 我得到了我想要的引荐来源网址,即站点在我的远程服务器中使用$loc = $_GET['location']; 安装脚本的位置,所以我必须在此脚本中插入document.location,但我现在不知道如何。

<script>
var src = "http://site.com/ref.php"
src += "?referrer=" + escape( document.referrer );
src += "&anticache=" + new Date().getTime();
var body = document.getElementsByTagName( "body" )[0];
var image = document.createElement( "img" );
image.src = src;
body.appendChild( image );
</script>

我已尝试添加到脚本 src += "?location=" + escape( document.location ); 但不工作 有什么帮助吗?

【问题讨论】:

  • 喜欢止痛技术
  • 无需将图像元素附加到正文 - 只需设置“src”属性就会导致 HTTP 事务。

标签: php javascript location referrer


【解决方案1】:
src += "?location=" + escape( document.location );

如果你把它放在referreranticache 参数之后,你已经得到了?;你想要的是一个 &amp; 来分隔两个参数。

使用location.href 优先于document.location,使用encodeURIComponent 优先于escape

【讨论】:

  • 我试过了,但没用,如果可以的话,给我正确的代码
  • 你还有两个?s,一个在location之前,一个在referrer之前。第二个必须是&amp;
  • 哦,encodeURIComponent 也适用于 referrer...几乎没有任何理由在 JavaScript 中使用 escape
【解决方案2】:

它不起作用,因为document.location 是一个包含许多信息的对象:see?。试试document.location.href

代码:

var src = "http://site.com/ref.php"
src += "?referrer=" + escape( document.referrer );
src += "&anticache=" + new Date().getTime();
src += "&location=" + encodeURIComponent( location.href );

【讨论】:

  • 问题是如果我添加到脚本行 src += "?location=" + escape(document.location.href);脚本不再起作用,我什么也得不到,没有推荐人,没有位置
猜你喜欢
  • 1970-01-01
  • 2015-06-16
  • 1970-01-01
  • 2019-01-28
  • 2012-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多