views:

397

answers:

2

Hi,

i load an external page with

 $('#myContainer').load('myfile.html');

in myfile.html theres an

<script type="text/javascript" src="otherscript.js"></script>

Some users report that the otherscript.js is not loaded... i've tested a all common browsers (firefox, ie 6/7, safari, opera etc.) - i cant figure out why this wont work...

an other think is... according to my firebug the browser wont cache the otherscript.js.. it loads with

otherscript.js?_=1234785

(timestamp here :) )

Anyone has an idea why some browsers doesnt support that and.. how can i enable that caching?

MFG Christopher

A: 

to avoid problems with the cache, you can do the following:

$('#myContainer').load('myfile.html?'+(new Date()).getTime());

in myfile.html:

<script type="text/javascript">

var script = document.createElement("script"); 
script.setAttribute('type','text/javascript'); 
script.setAttribute('src','otherscript.js?'+(new Date()).getTime()); 
document.body.appendChild(script);

</script>

accommodating this code to your need.

andres descalzo
hm... no i mean jquery or .. dont know what adds the timestamp... and i dont want to :)
Beerweasle
+1  A: 

The .load functions only loads html. Since you are not allowed to load external scripts in to the browser by the browser security protocol. But luckily there's .getScript to get around this. Check it out: http://docs.jquery.com/Ajax/jQuery.getScript

..fredrik

fredrik