君语贤
时光静好,与君语;细水流年,与君同;繁华落尽,与君老...

前端设计>JS>正文

站群或者多个网站判断调用CNZZ代码

2019-05-04 17:34 君语贤CNZZ判断调用

网站对于功能性代码,如CNZZ这种代码,假设你有50个站点,实际只需要调用一个js就可以分别对50个站点独立监控,以免写很多个js,这样也便于操作。如创建一个公共js:cnzz.js。代码内容为:

thisURL = document.URL;
var sign_url =null;
document.write('<span style="display:none">');

//www.weguiding.com  的统计代
if(thisURL.indexOf('www.weguiding.com')>0)
{
var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1271191319'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1271191319' type='text/javascript'%3E%3C/script%3E"));}


//m.weguiding.com 的统计代码
if(thisURL.indexOf('m.weguiding.com')>0)
{
var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1261060817'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.cnzz.com/z_stat.php%3Fid%3D1261060817' type='text/javascript'%3E%3C/script%3E"));
}

document.writeln('</span>');

核心技巧为:通过js判断当前域名,然后自动调用当前域名的cnzz对代码。

if花括号中填写以下图示中脚本标签中包含的内容即可

站群或者多个网站判断调用CNZZ代码

多站点的添加直接复制下图中的机构体,修改对应的域名和cnzz代码即可

站群或者多个网站判断调用CNZZ代码

本文链接:https://www.weguiding.com/js/418.html