我有一个像素,当我加载它时,它说:
a call to document.write() from an asynchronously-loaded external script was ignored
然后显示:
document.getElementById('gospixel') is null
这是我的像素代码:
<script name="gospix" src="http://www.example.com/p/gospixel.js">
并在该文件中:
gos_f=42;
gos_a1='a2';
gos_u=window.location.href;
gos_k='6gZYlfy7Y7Q';
gos_rt='3_s';
document.write(unescape("%3Cscript src='http://example.com/p/gosuna.js' type='text/javascript'%3E%3C/script%3E"));
感谢您的帮助!
答案 0 :(得分:22)
不要使用document.write。查看此主题:Why is document.write considered a "bad practice"?
相反,使用像document.createElement和appendChild这样的动态对象。
http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/
这将解决您的错误。
答案 1 :(得分:0)
用
替换最后一行function insertScript(){
document.write(unescape("%3Cscript src='http://example.com/p/gosuna.js' type='text/javascript'%3E%3C/script%3E"));
}
然后在html的其他部分
<script type="text/javascript">
insertScript();
</script>