Link to home
Start Free TrialLog in
Avatar of adworldmedia
adworldmediaFlag for United States of America

asked on

Insert JavaScript & Function Call via DOM

I am attempting to insert a Javascript source via the DOM (which I've figured out), and then insert a Javascript tag to call a function in that JavaScript source.

I'm finding that when I do this via the DOM, the function fails because the source is not fully loaded.

How can I fix this?  Do I need to wait till the source is fully loaded before I inject the function call?

var _script = document.createElement("script");
_script.src = "http://cluster.pppp.com/includes/z.js";
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(_script);
var headID = document.getElementsByTagName('body')[0];
var _script2 = document.createElement("script");
_script2.innerHTML = 'aarun(22664,4870);';
_script2.type = 'text/javascript';
headID.appendChild(_script2);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of adworldmedia
adworldmedia
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial