chrome報錯a parser-blocking, cross-origin script, is invoked via document.write.

確切的說是警告,內容是:javascript

A Parser-blocking, cross-origin script, http://s4.cnzz.com/stat.php?id=xxx&show=pic, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity.php

錯誤緣由是:頁面渲染完成後使用了document.write()(cnzz統計代碼引發的,chrome53以上版本會報錯。)。java

解決方案:將統計代碼改成異步加載chrome

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 = 'https://w.cnzz.com/c.php?id=xxxxxx&async=1';
var root_s = document.getElementsByTagName('script')[0];
root_s.parentNode.insertBefore(cnzz_s_tag, root_s);

 

stackoverflow傳送門:http://stackoverflow.com/questions/39610829/a-parser-blocking-cross-origin-script-is-invoked-via-document-write-how-to-ci異步

相關文章
相關標籤/搜索