象Google的广告,展示啥内容,都是由Google自己控制的,使用普通的页面提交连接的方式,我们是无法统计我们页面上的Google广告被点击了多少次,被谁点击了。因为这些页面都不受我们控制。
下面介绍一个可以统计Google那样广告点击次数的方法。
1<html>
2<head>
3<title>点击计数</title>
4<script language="javascript">
5<!--
6function keyDown(e)
7{
8if (event.srcElement.tagName=='IFRAME'
9&& event.clientX==-1
10&& event.clientY==-1
11&& event.fromElement=='[object]'){
12// 如果需要向其他页面提交
13//document.adform.submit();
14var num = parseInt(shownum.innerHTML);
15shownum.innerHTML = num + 1;
16}
17return false;
18}
19document.onmousemove=keyDown;
20document.onmouseover=keyDown ;
21document.onmouseout=keyDown ;
22document.onblur=keyDown;
23//-->
24</script>
25</head>
26<body>
27<!-- 如果需要向另外一个页面传递参数,可以用下面的方式//-->
28<form action="ad_click.php" method="post" name="adform" target="ad_click">
29<input id="uid" name="uid" type="hidden" value="1922"/>
30<input id="keyid" name="keyid" type="hidden" value="1119342517"/>
31<input id="aid" name="aid" type="hidden"/>
32</form>
33<iframe frameborder="0" height="0" marginheight="0" marginwidth="0" name="ad_click" scrolling="no" src="about:blank" width="0">
34</iframe>
35<!--页面提交代码结束//--> 点击IFrame中的次数:<div id="shownum">
360</div>
37<iframe frameborder="0" height="100" marginheight="0" marginwidth="0" name="ad_click" scrolling="no" src="http://www.yesky.net/" style="width: 616px; height: 171px" width="100">
38</iframe>
39<br/>
40<br/>
41<a href=" http://blog.joycode.com/ " target="_blank">本页其它连接</a>
42</body>
43</html>
上述代码中,我们在点击、移动等事件中,判断用户点击的是不是某个需要的范围内。然后进行计数,如果我们需要额外的记录,可以在这些事件函数中,向一个我们可控的页面进行提交。为了不影响页面的展示,这个页面被提交的页面,是在一个隐含的IFrame中实现的,具体看上述代码就明白了。
通过以上的方法,我们就可以实现不论点本网站的自己广告,还是Google广告,每点击一次,增加多少可用分这类的逻辑了。(当然这个逻辑可以更复杂)