...

View Full Version : Reload a js file and nothin else....



JAVAEOC
02-11-2004, 11:52 PM
Well, i just want to reload my js file nothing else

thanks for any help

Roy Sinclair
02-12-2004, 03:23 PM
Ask in the DOM forum about inserting a "new" script tag. It may be possible to insert one and that would cause a copy of the script to be loaded but whether it would use a fresh copy retrieved from the server or the copy already cached is anyone's guess.

Garadon
02-12-2004, 04:47 PM
How I would do it.

<script id="test" src="test.js" type="text/javascript"></script>
<script>
function test()
{
scriptBlock=document.getElementById('test');
scriptBlock.src=scriptBlock.src;
}</script>

liorean
02-12-2004, 05:02 PM
I would personally wrap everything except global variable and function declarations in a function, and call that function again if needed, instead of trying to load the script again. There's no guarantee toward whether the file will be called from cache or reloaded at all, and there is no guarantee that the file will be executed again if it is in fact reloaded. Op7 before 7.5 did neither load the file, not execute the script if you wrote it into the file dynamically. Saf1.2 still does neither. Ie5m does only load the file if the script element is written through innerHTML instead of dynamically created.

Garadon
02-12-2004, 05:49 PM
migth be me that are wrong here but reload ain't that simply when it calls the file from whatever source it find it at.
and refresh is when it force downloads a new copy of the requesten file? :)

anyway perhaps I should write 'IE6 Scripter ONLY' in my sig :)

JAVAEOC
02-12-2004, 11:35 PM
Well the thing is that when i just chage the src of the script element it doesnt execute the js file again.

then i have to reload the whole page.... which takes tooo long in some cases :)

liorean
02-13-2004, 12:22 AM
The src of scripts is read only for practical reasons. You have to create a new script element for it to load anew, in the browsers that does that.

JAVAEOC
02-13-2004, 01:05 AM
how?

liorean
02-13-2004, 01:27 AM
For iew, moz and op7.5:
var
oScript=document.createElement('script');
oScript.type='text/javascript';
oScript.src=sAddress;
document.getElementsByTagName('head').item(0).appendChild(oScript);
For iem:
var
oDiv=document.createElement('div');
oDiv.innerHTML='<script type="text/javascript" src="'+sAddress+'"><\/script>';
For Saf1.2 (only works on files in the same domain):
var
oFile=new XMLHttpRequest;
oFile.open('GET',sAddress,false);
oFile.send('');
eval(oFile.responseText);

The saf code also works in moz, but may crash the browser in some cases.

JAVAEOC
02-14-2004, 12:01 AM
thanks alot



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum