I have a page where I am loading another remote source using a element. Everything works great, except, now I want to be able to change the 'src' of the script depending on certain conditions when loading the page. The problem is, when I change the 'src', even though it changes in the DOM, it has no affect. The original 'src' is used and never updated.
Is it possible to dynamically retrieve the source of a remote site, or does this value have to be constant?
Edit: here is a sample of what I'm attempting:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://voap.weather.com/weather/oap/90210?
template=GENXV&par=3000000007&unit=0&key=XXX"></script>
<script>
$(document).ready(function(){
var newS = document.createElement('script');
newS.type = "text/javascript";
newS.src = "http://voap.weather.com/weather/oap/90210?template=GENXV&par=3000000007&unit=0&key=XXX";
$("head").append (newS);
});
</script>
</head>
<body>
</body>
</html>
You will notice that the 'script' which is at the top works fine. The script I attempt to add dynamically does not work at all. It shows up in the DOM-inspector, but not in the page.
Also, see the following:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.getScript("http://w3schools.com/jquery/demo_ajax_script.js");
$.getScript("http://voap.weather.com/weather/oap/90210?template=GENXV&par=3000000007&unit=0&key=XXX");
});
</script>
</head>
<body>
</body>
</html>
In this example, the w3school example works, but the weather does not.