js跨域实现统计
前端js部分function addJs(file){var scriptId=arguments;var funExec=arguments;var funcLoading=arguments;var expire=arguments;var expFunc=arguments;var parent=document.getElementsByTagName('head');if($('scriptId')){var script=$('scriptId');script.src=file;}else{var script=document.createElement('SCRIPT');script.setAttribute('type', 'text/javascript');script.setAttribute('src', file);script.setAttribute('id', scriptId);parent.appendChild(script);}script.onreadystatechange =function (){if(typeof(funExec)=='function'){if(script.readyState == 'complete' || script.readyState =="loaded"){funExec()}}if(script.readyState == 'loading'&&typeof(funcLoading)=='function'){t=setTimeout(funcLoading ,expire )}};script.onload = function (){(typeof(funExec)=='function')?funExec():""};return script;}function downcount(){addJs("http://localhost/count.php?click=1&"+Math.random());//jQuery.getJSON(//"http://www.ttcj.cn/count.php?click=1&"+Math.random(),//function(json){//$("count").innerHTML=json;//}//);}function $(id){return document.getElementById(id);}
count.php处理部分
if($_GET['click']==1){if(file_exists("count.txt")){$count=file_get_contents('count.txt');$count=$count+1;Tools::writeFile($count,'count.txt');echo 'document.getElementById("count").innerHTML='.$count;}else{Tools::writeFile('1000','count.txt');echo 'document.getElementById("count").innerHTML=12';//echo '12';}}else{$count=file_get_contents('count.txt');echo 'document.write("'.$count.'")';}
页:
[1]