473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Dynamically loading external javascript files.

Hello All,

I have been struggling with a cross browser solution to loading
external javascript files on the fly.

I have been successful using the following code in IE6:

var newScr = document.createElement("SCRIPT");
newScr.src = "newScr.js";
newScr.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(newScr);

I believe the reason is that IE is loading the external file
syncronously while Firefox is not. Is there an onload event for
creating an element (if so I do not see it in Venkman). I have seen the
solution of using XMLHTTP to load the script but I am trying to get
around any dependency (atleast at this stage of the library) on
activex.

Thanks in advance for any help.

Apr 14 '06 #1
1 3764
oz*********@gmail.com said the following on 4/14/2006 3:49 PM:
Hello All,

I have been struggling with a cross browser solution to loading
external javascript files on the fly.
What is the problem you are having?
I have been successful using the following code in IE6:

var newScr = document.createElement("SCRIPT");
newScr.src = "newScr.js";
newScr.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(newScr);
That code is successful in Opera and Mozilla as well.
I believe the reason is that IE is loading the external file
syncronously while Firefox is not. Is there an onload event for
creating an element (if so I do not see it in Venkman).
You could try newScr.onload = itsLoaded;

Works in Opera9 and Firefox but not in IE6.

What it sounds like you are trying to do is something like this:

var newScr = document.createElement("SCRIPT");
newScr.src = "newScr.js";
newScr.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(newScr);

//code here to do something with the code in newScr.js

If that is true, the simplest most reliable way is to have newScr.js to
let you know when its loaded:

newScr.js:
//data here
functionCall();

Where functionCall() is in the main page that is loading the document.
Then, that function never gets called until after the data is loaded.
It's a timing issue.
I have seen the solution of using XMLHTTP to load the script but
I am trying to get around any dependency (atleast at this stage
of the library) on activex.


XMLHTTPRequest is probably the *worst* way to accomplish dynamic script
loading.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
2
by: christine.nguyen | last post by:
Hello all, I have a page called test.html. Within test.html I have an iframe whose source is mypage.html. When mypage.html loads, it dynamically creates a javascript element which contains a...
9
by: Donius | last post by:
Hey everyone, i am doing some stuff where i'd like to pop up a little confirmation before a user clicks on a 'delete' link. Just trying to keep the markup clean, i added an attribute ...
4
by: max | last post by:
Hello, Based on various posts, I've come up with the following code to load data into a js array dynamically without a screen refresh. It works, but you have to push the button twice before it...
2
by: 20050407 prerelease | last post by:
Hi! Is it possible in a fairly portable manner to load additional javascript code from a WWW URL? This would be useful for large-scale projects.
2
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder....
6
by: Venkatesh | last post by:
Hello All, I have couple of doubts regarding the concept of on-demand javascript loading using javascript code. I could see on the net different techniques for achieving this - techniques like:...
6
by: ernesto.tejeda | last post by:
Hello, I have a couple of questions regarding the loading of .js files for the browser and would like anyone to point me wher to find the answer (or if you know the answer and tell me will do just...
20
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.