document.write become invalid within Javascript file which is added by appendChild -


when add script tag in body tag of index.html directly, below:

<script type="text/javascript" src='**doc_write_in_it.js**'></script> 

it works well, "test doc write" output there.

but if write in way, below:

<script type="text/javascript">     var model = document.createelement('script');     model.setattribute('type','text/javascript');     model.setattribute('src','doc_write_in_it.js');     var bd = document.getelementsbytagname('body')[0];     bd.appendchild(model); </script>    

document.write become invalid within javascript file added appendchild.

the alert in doc_write_in_it.js show, text in document.write doesn't.

doc_write_in_it.js file this:

alert('activited'); document.write('test doc write"); 

hope can help... lot...

as mentioned above, document.write not work when page has been loaded. suggest use innerhtml property whenever can.

example:

var bd = document.getelementsbytagname('body')[0]; bd.innerhtml = "some text"; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -