最近在给网站添加cnzz统计代码的时候,发现谷歌浏览器下报出了警告,如下
A Parser-blocking, cross site (i.e. different eTLD+1) script,https://c.cnzz.com/core.php?web_id=1261852234&t=z, is invoked via document.write. This MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message.Seehttps://www.chromestatus.com/feature/5718547946799104for more details. na @ z_stat.php?id=1261852234&web_id=1261852234:16
经过查询发现和谷歌浏览器的更新有关。具体错误原因为:
页面渲染完成后使用了document.write()(chrome53以上版本会报错。)。
解决办法:将统计代码改为异步加载(这种方式无法显示cnzz统计图标)
1、找到原来的统计代码,如
<scriptsrc="https://s95.cnzz.com/z_stat.php?id=1261852234&web_id=1261852234"language="JavaScript">
拷贝 id=1261852234 中的数字
2、将拷贝的数字,替换到下面代码中的“XXXXXXXX”
var cnzz_s_tag = document.createElement('script');
cnzz_s_tag.type = 'text/javascript';
cnzz_s_tag.async = true;
cnzz_s_tag.charset = “utf-8”;
cnzz_s_tag.src = “http://w.cnzz.com/c.php?id=XXXXXXXX&async=1”;var root_s = document.getElementsByTagName('script')[0];
root_s.parentNode.insertBefore(cnzz_s_tag, root_s);
3、将如上统计代码加入页面上传至服务器即可