开发者

My div does not exists after loading my pixel

I have a pixel and when I load it, it says:

a call to document.write() from an asynchronously-loaded external script was ignored

and then displays:

document.getElementById('gospixel') is null

Here's my pixel code:

<script name="gospix" src="http://www.example.com/p/gospixel.js">

and in that file:

gos_f=42;
gos_a1='a2';
gos_u=w开发者_StackOverflow中文版indow.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"));

Thanks for your help!


Don't use document.write. view this thread: Why is document.write considered a "bad practice"?

Instead, use dynamic object like document.createElement and appendChild.

http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/

This will slove your error.


apparently, the browser is ignoring the autowrite from the import (for security reasons, so an imported script can't modify your page), so you should try making the insert on demand

in gospixel replace the last line with

function insertScript(){
    document.write(unescape("%3Cscript src='http://example.com/p/gosuna.js' type='text/javascript'%3E%3C/script%3E"));
}

and then on some other part of the html

<script type="text/javascript">
    insertScript();
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜