View Full Version : Problem loading *.js files

Oct 28th, 2002, 02:32 AM
Ok, here's how this works, I need to load a clients info every time they log in, so I work with cookies - a name that represents a js file and a pass that gets cleared in any perl based changes to said js file, I set all the needed functions up and they work great with a static js (<script src="test.js></script>) but I need this to be dynamic, so:

var scriptTag = document.getElementById('loadScript');
var head = document.getElementsByTagName('head').item(0)
if(scriptTag) head.removeChild(scriptTag);
script = document.createElement('script');
script.src = "users/"+sell_it+".js";
script.type = 'text/javascript';
script.id = 'loadScript';

first off the removeChild and everything above applies to the admin - level of the script, it loads all client js files (with use of a drop down) and so needs to be replaced to stop different client files getting muddled, the sell_it variable is the name of the js file - held in the cookie or in this case the drop down.

--finally to the problem, I have an iframe on the page that holds and handles perl (for easy feedback) but once the above script is run I cant get access to the iframe, I think its because the js file doesn't finish loading -for some reason, so technically the page hasn't loaded and the frames[''] isn't available...?

Any comment on this would be greatly appreciated, I've been working on this for hours and I get the feeling its something simple I'm missing.

Oct 28th, 2002, 04:14 PM
I know this is the problem, the loading bar in NS shows full forever, I've had similar probs with onClick before (but only in NS - this is happening in both browsers). Is there no way I can force this to load? I've checked the removeChild part, working fine, tried handing it a solid string to src didn't make any difference.

Checked and double checked the frame code, it works fine with the static js file,

Frames['the_frm'].getElementById('the_info').innerHTML='the new js files info';
The error is: Error: frames['the_frm '] has no properties

Oct 28th, 2002, 08:34 PM
Frames['the_frm'].document.getElementById('the_info').innerHTML='the new js files info';

also, are you sure that the frame has finished loading at the point when you're calling this function. if it hasn't, then that might be why you're having a problem

Oct 28th, 2002, 09:48 PM
Sorry, that’s a typo, I do have ‘document’ in the code, still isn’t recognising the iframe,

The iframe itself is actualy loaded, (I can access it before I run the load-js function).

I realise that I’m guessing here, but I think that the browser makes the frames array after the page has fully loaded, when I load the js file that flag gets changed to ‘page still loading’ and somehow it doesn’t get changed back.