Accessing dynamically loaded variables

D

dnn

How can I access dynamically loaded variables?

I am trying to load an external javascript file dynamically and then
access its variables. The script is loaded by the onload handler.

The code looks like this:
var constants = document.createElement("script");
constants.src = REL_PATH + "extensions_demo/js/constants_" +
MY_LANGUAGE + ".js";
constants.type ="text/javascript";
document.getElementsByTagName("head")[0].appendChild(constants);
alert(window.ROOM_01); // ROOM_01 is a variable out of the external
file

However alert(window.ROOM_01) returns 'undefined'. How can the
variables of the dynamically loaded file be accessed?

Thanx for helping.

Cheers,
Nico
 
R

Randy Webb

dnn said the following on 6/29/2006 4:45 AM:
How can I access dynamically loaded variables?

I am trying to load an external javascript file dynamically and then
access its variables. The script is loaded by the onload handler.

The code looks like this:
var constants = document.createElement("script");
constants.src = REL_PATH + "extensions_demo/js/constants_" + MY_LANGUAGE + ".js";
constants.type ="text/javascript";
document.getElementsByTagName("head")[0].appendChild(constants);
alert(window.ROOM_01); // ROOM_01 is a variable out of the external file

However alert(window.ROOM_01) returns 'undefined'. How can the
variables of the dynamically loaded file be accessed?

Either by ROOM_01 or window.ROOM_01 or window['ROOM_01']

If it is alerting undefined then something is wrong in your src path.
Or, ROOM_01 is not a global variable.

Try alerting constants.src and make sure it is what you wanted it to be
and that it is a valid path.

Put an alert in the external file to make sure it is getting loaded.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top