I'm having a problem when I use appendChild()
to append a <script>
tag where the javascript referenced in the new script tag is not run. In Firebug I get a notification which says "Reload the page to get source" but if I reload the JS will be appendChild again.
Here is my code:
var divAd = document.createElement("div");
divAd.innerHTML = '<script src="http:example/adenseload.js" language="javascript" type="text/javascript"></script>';
titleBak.appendChild(divAd);
How can I use the appended JS after using appendChild()?
Thanks for your answer.
I'm having a problem when I use appendChild()
to append a <script>
tag where the javascript referenced in the new script tag is not run. In Firebug I get a notification which says "Reload the page to get source" but if I reload the JS will be appendChild again.
Here is my code:
var divAd = document.createElement("div");
divAd.innerHTML = '<script src="http:example./adenseload.js" language="javascript" type="text/javascript"></script>';
titleBak.appendChild(divAd);
How can I use the appended JS after using appendChild()?
Thanks for your answer.
Share Improve this question edited Nov 17, 2011 at 11:08 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Nov 17, 2011 at 10:56 viyancsviyancs 2,3394 gold badges40 silver badges72 bronze badges 2- are you sure that the src-property is correct and the loaded js-file actually calls a method after being loaded? – Michael Sandino Commented Nov 17, 2011 at 10:59
- yes the src is corrent.i'm appendChild() when load document in another js. – viyancs Commented Nov 17, 2011 at 11:04
2 Answers
Reset to default 4Don't wrap it in a div, create the script tag directly. This worked for me:
var scriptTag = document.createElement("script");
scriptTag.src = "http://example./myscript.js";
bodyTag.appendChild(scriptTag);
You have to use below statement to load JS,document.write('<script src="', 'http:example./adenseload.js', '" type="text/JavaScript"><\/script>');
.
you can append HTMLobjects only to the DIV, Not script tags
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745079850a4610057.html
评论列表(0条)