0

i'm trying add external javascript code with this code:

function get_js(b){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = b;
head.appendChild(script);
    }

This external javascript code using document.write inside:

document.write('<script language="JavaScript">document.write(\'<div id="something" style="position: fixed; top: 0; bottom: 0; left: 0; right: 0;">&nbsp;<\/div>\');...

When i'm trying execute function from this file, i'm getting this error:

ReferenceError: some_function is not defined

I thought that document.write in JS code is problem. Can anybody help me?

Thanks in advance!

///

OK, figured it out with POSTSCRIBE: https://github.com/krux/postscribe

D. Nagga
  • 31
  • 3

1 Answers1

2

don't use document.write(). If you call document.write() after the page is load, it will "reopen" the pageload and as a sideeffect clear everything from the screen.

take a look at properties/methods like innerHTML, textContent, document.createElement(), appendChild(), ...

Thomas
  • 3,245
  • 1
  • 10
  • 8