js跨域实现统计

前端js部分

function addJs(file)
{
var scriptId=arguments[1];
var funExec=arguments[2];
var funcLoading=arguments[3];
var expire=arguments[4];
var expFunc=arguments[5];
var parent=document.getElementsByTagName('head')[0];
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.'")';
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值