下面介紹一個可以統(tǒng)計Google那樣廣告點擊次數(shù)的方法。
<html>
<head>
<title>點擊計數(shù)< SPAN>title> <script language="javascript"> < SPAN>script>
< SPAN>head>
<body>
![]()
<form name="adform" method="post" action="ad_click.php" target='ad_click'>
="uid" value='1922' type="hidden" id="uid">
<input name="keyid" type="hidden"
value='1119342517' id="keyid">
<input name="aid" type="hidden" id="aid">
< SPAN>form>
<iframe name='ad_click' marginwidth="0"
marginheight="0" frameborder="0" scrolling="no"
src='about:blank' width="0" height="0">
< SPAN>iframe>
![]()
![]()
點擊IFrame中的次數(shù):
<div id="shownum">0< SPAN>div>
<iframe name='ad_click' marginwidth="0"
marginheight="0" frameborder="0" scrolling="no"
src='http://www.yesky.net/' width="100"
height="100" style="width: 616px; height: 171px">
< SPAN>iframe>
<br />
<br />
<a href="http://blog.joycode.com/" target="_blank">本頁其它連接< SPAN>a>
< SPAN>body>
< SPAN>html>
上述代碼中,我們在點擊、移動等事件中,判斷用戶點擊的是不是某個需要的范圍內(nèi)。然后進行計數(shù),如果我們需要額外的記錄,可以在這些事件函數(shù)中,向一個我們可控的頁面進行提交。為了不影響頁面的展示,這個頁面被提交的頁面,是在一個隱含的IFrame中實現(xiàn)的,具體看上述代碼就明白了。
通過以上的方法,我們就可以實現(xiàn)不論點本網(wǎng)站的自己廣告,還是Google廣告,每點擊一次,增加多少可用分這類的邏輯了。(當然這個邏輯可以更復雜)