Menu
Apparently this isnt possible:
<SCRIPT>
var filen = “data.js”;
</SCRIPT>
<script SRC=’filen’ type=”text/javascript”></script>
So how do I make it load a file named a string? The thing is – I need it to load 1data.js, 2data.js, etc. – depending on what a variable is set to in the script.
[code=html]<html>
<head>
<title>
script loading
</title>
<script type="text/javascript">
function loadScript (url) {
if (document.layers)
window.location.href = url;
else if (document.getElementById) {
var script = document.createElement('script');
script.defer = true;
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
}
</script>
</head>
<body>
<form name="gui">
<input type="button" value="load script"
onclick="loadScript('whatever.js')"
/>
<input type="button" value="call f"
onclick="f();"
/>
</form>
<p>
Kibology
</p>
</body>
</html>[/code]
<i>
</i><script language="JavaScript" src="my.js">
Hmm, thats not working for me.
Is there any other way to load a file in javascript?[/QUOTE]
Why don't you just use
<i>
</i><script language="JavaScript" src="my.js">
What is wrong with doing it like that?[/QUOTE]
[CODE]<script type="text/javascript">
var filen = "data.js";
document.write("<script SRC='"+filen+"' type='text/javascript'></script>");
</script>[/CODE]
There would be a link here, but apparently, my site is "a competing site". I guess they are scared of my 13 registered members.[/QUOTE]
Good solution for external JavaScript libraries... Anybody know a solution for adding executable script -- without using [b]eval()[/b] -- that, say, is retrieved as source code via an Ajax request? All I know is that this is one case where [b]innerHTML[/b] will NOT work for this purpose. ?[/QUOTE]I found this at
[CODE]var sHTML="<input type=button onclick=" +
"go2()" + " value='Click Me'><BR>"
var sScript='<SCRIPT DEFER>'
sScript = sScript +
'function go2(){ alert("Hello from inserted script.") }'
sScript = sScript + '</script' + '>';
ScriptDiv.insertAdjacentHTML("afterBegin",sHTML + sScript);[/CODE]
well, a simple answer is this. i don't know if it's what you want, though...
[CODE]<script type="text/javascript">
[/QUOTE]
var filen = "data.js";
document.write("<script SRC='"+filen+"' type='text/javascript'></script>");
</script>[/CODE]
I found this athttp://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertadjacenthtml.asp
I haven't tried it but it looks promising.[/QUOTE]
That page says "there is no public standard that applies to this method". Is this still correct? Is [B]insertAdjacentHTML()[/B] not part of the standards?[/QUOTE]I wouldn't know, today is the first time I've heard of it.
That doesn't explain how you got your script inserted into the page. That is only how to retrieve information from the server via Ajax.[/QUOTE]
<script SRC='filen' type="text/javascript"></script>
The thing is - I need it to load 1data.js, 2data.js, etc. - depending on what a variable is set to in the script.[/QUOTE]
Please excuse me for saying so, but I'd give serious consideration to growing up and change that little gripe, of yours, too. Do you think IBM should give free advertising to whomever their smallest competitor may be? Do you think MS should give free advertising to whomever the smallest competitor for MS Office may be? In addition, if these big name companies were to give free advertising for their smallest competitors, do you not see how that is an endorsement of the competitor? Seems pretty unreasonable, to me, if such a small competitor were to go all sour grapes over getting refused free advertising. Plus, if this small competitor were to start taking out more free advertising griping about getting refused, me thinks the world in general would certainly get an immediate picture of the supposed "quality" of the ownership of such a small business -- and it would NOT be a *good* picture.[/QUOTE]
Anybody know a solution for adding executable script -- without using eval() -- that, say, is retrieved as source code via an Ajax request? All I know is that this is one case where innerHTML will NOT work for this purpose.
[/QUOTE]
<i>
</i><html>
<head>
<script language="javascript">
var fs=false;
if(typeof ActiveXObject != "undefined"){
try {
fs = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
fs = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
fs = false;
}
}
}
if (!fs && typeof XMLHttpRequest != "undefined") {
try {
fs = new XMLHttpRequest();
} catch (e) {
fs=false;
}
}
if (!fs && window.createRequest) {
try {
fs = window.createRequest();
} catch (e) {
fs=false;
}
}
function getScript(){
fs.open("GET", "myfile.html", true);
fs.onreadystatechange = function(){
if (fs.readyState==4){
text = fs.responseText;
alert(text)
//[\w|\W]+ [\w|\W]+
r = new RegExp("[\w|\W]+<script.*>([\w|\W]+)</script>[\w|\W]+","i");
scripts = new Array();
while(text.match(r)){
scripts[scripts.length] = text.replace(r,"$1");
text = text.replace(r,"-");
alert(scripts);
}
newScript = document.createElement("script");
newScript.language = "JavaScript";
theScript = document.createTextNode(text);
newScript.appendChild(theScript);
document.getElementsByTagName("head")[0].appendChild(newScript);
}
}
fs.send(null);
}
</script>
</head>
<body>
<input type="button" onClick="getScript()" value="Click Me!">
</body>
</html>
0.1.9 — BETA 6.17