cnzz代碼添加元素到頁面
來源:程序員人生 發布時間:2014-12-08 09:01:37 閱讀次數:5100次
首先在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>"
他創建了1個span元素,添加了1個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⑻" type="text/javascript"></script>
關于其流量統計的原理,大家可以參看這篇文章:CNZZ網站流量統計原理簡析
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈