我有以下代码来在不支持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 += "?location=" + escape( document.location );
如果将其放在
referrer
或anticache
参数后面,则已经有?
;您想要的是一个&
来分隔两个参数。location.href
优先使用document.location
,encodeURIComponent
优先使用escape
。