我有一个基本的html页面,其中有指向不同站点的链接。我想要做的就是跟踪点击次数。我这样做是通过在链接的Click事件上发送一个0像素图像调用而不在点击事件上返回false。链接点击跟踪在Safari浏览器上不起作用
对于除Safari之外的所有浏览器(在Windows操作系统上),这同样工作正常。
当使用javascript点击链接时我延迟重定向并发送图像请求到服务器并记录点击服务器端。我试图增加延迟,但没有成功......追踪器在除Safari之外的所有浏览器上工作gr8,它根本没有发送请求。
我不知道为什么,但可能它对于整个JS野生动物园等待发出请求之前,整个JS执行的时候被重定向后执行....
======= ==================================================
<html>
<head>
<script type="text/javascript">
function logEvent(){
image = new Image(1,1);
image.onLoad=function(){alert("Loaded");};
image.onLoad=function(){alert("Error");};
image.src='http://#path_to_logger_php#/log.php?'+Math.random(0, 1000) + '=' + Math.random(0, 1000);
pauseRedirect(500);
}
function pauseRedirect(millis){
var date = new Date();
var curDate = null;
do {curDate = new Date();}
while(curDate-date < millis);
}
</script>
</head>
<body>
<a href="http://www.google.com" onclick="logEvent(); return true;">Site 1</a><br/>
<a href="http://www.yahoo.com" onclick="logEvent(); return true;">Site 2</a><br/>
</body>
</html>
=========================================== ==============
代码适用于chrome,firefox,ie和Opera。不适用于Safari只有.....任何线索....
你是否在等待图像完成加载或做像`setTimeout()`?我们可以看到一些代码吗? – alex 2011-02-09 13:54:52