Solved

Insert JavaScript & Function Call via DOM

Posted on 2014-01-29
1
313 Views
Last Modified: 2014-01-29
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

0
Comment
Question by:adworldmedia
1 Comment
 

Accepted Solution

by:
adworldmedia earned 0 total points
ID: 39818248
I figured it out...

I used the .onload event to fire a function when the source is loaded, and that function adds the function call.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now