Why add a script when you’ve already got one that’s usable?
You don’t need to bother loading jQuery. It’s not needed in this instance. The changeScript function will work. Works on all my browsers, my friends Nokia 5800, all iPhones that have tested it
as it will not load src1.js (just found that out, trying to minimize the number of file being used)
changeScript(“src2.js”) can however be put in src1.js, and both will be called
This will work, even though the script you’re changing is the one you’re using
<body>
<script type="text/javascript">
function changeScript(livescript_equation) {
oldScript=document.getElementsByTagName("script")[0];
var newEl=document.createElement('script');
newEl.setAttribute('type', 'text/javascript');
newEl.setAttribute('src',livescript_equation);
oldScript.parentNode.replaceChild(newEl,oldScript);
}
window.onload=function(){
changeScript("src1.js");
}
</script>
Unlike CSS stylesheet changers, the javascript will be kept in memory, so you can keep using this method to build layers of scripting. Look in to cache headers and expiry dates as well, really useful when using this type of script
var hh = document.getElementsByTagName(‘head’)[0];
a.htm
<head>
<script type="text/javascript">
var h = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.setAttribute("type","text/javascript");
s.setAttribute("src","a.js");
h.appendChild(s);
alert(h.innerHTML);
</script>
</head>
<body>
a.js
var n="The Time Through Ages. In the Name of Allah, Most Gracious, Most Merciful. 1. By the Time, 2. Verily Man is in loss, 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.";
alert(n);