16

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=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"));

Thanks for your help!

Ates Goral
  • 126,894
  • 24
  • 129
  • 188
Tech4Wilco
  • 6,620
  • 3
  • 43
  • 80

2 Answers2

22

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.

Community
  • 1
  • 1
Pat R Ellery
  • 1,566
  • 1
  • 21
  • 39
0

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>
Einacio
  • 3,400
  • 1
  • 14
  • 19