cnzz代码添加元素到页面

首先在cnzz上注册账号后,他会给你如下代码:

<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cspan id='cnzz_stat_icon_xxxxxxxxxx'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1252929438%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));</script>

 这段js代码的意思是:

根据当前页面所使用的传输协议来定义变量cnzz_protocol,如果是https协议,则cnzz_protocol="https://",否则为="http://"。

document.write()这个命令简单地打印指定的文本内容到页面上。

unescape() 函数可对通过 escape() 编码的字符串进行解码。站长工具,我是在这里解码的,大家可以百度“unescape解码”,有很多在线解码工具的。

通过unescape()函数解码,我们可以得到:

"<span id='cnzz_stat_icon_1252929438'></span><script src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php?id=xxxxxxxxxx&show=pic1' type='text/javascript'></script>"

他创建了一个span元素,添加了一个script。

这个script执行完毕后,页面变成下面

<span id="cnzz_stat_icon_1252929438">
    <a href="http://www.cnzz.com/stat/website.php?web_id=xxxxxxxxxx" target="_blank" title="站长统计">
        <img src="http://icon.cnzz.com/img/pic1.gif" border="0" hspace="0" vspace="0">
    </a>
</span>
<script src="http://s19.cnzz.com/z_stat.php?id=xxxxxxxxxx&show=pic1" type="text/javascript"></script>
<script src="http://c.cnzz.com/core.php?web_id=xxxxxxxxxx&show=pic1&t=z" charset="utf-8" type="text/javascript"></script>

关于其流量统计的原理,大家可以参看这篇文章:CNZZ网站流量统计原理简析

posted on 2014-12-05 17:00  humingX  阅读(3607)  评论(1编辑  收藏  举报

导航