Forum Moderators: open

Message Too Old, No Replies

load javascript from variable

         

drofluga

1:07 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



hi there,

i have the folowing problem:

i have to load dynamically javascripts with different names (in this scripts are only document.write() things) . I tried to solve this with variables in this way:


<script language="JavaScript" src='http://www.somewhere..'+location.search>
</script>

does anybody know how to solve this problem?

MonkeeSage

3:35 pm on Sep 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should do the trick...
<script type="text/javascript">
<!--
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "http://www.somewhere.." + location.search;
document.getElementsByTagName("head")[0].appendChild(s);
//-->
</script>

Jordan

drofluga

6:12 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



it dont work currently. perhaps i made a mistake. how to load the file? I am new to JavaScript. I tried the following things:

<html>
<head>
</head>
<body>
<a href="ThisSite.html?c=1561&u=3">load </a>
<br>
<a href="ThisSite.html?c=1561&u=2" >load 2</a>
<br>

<script type="text/javascript">
<!--
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "http://www.betterupdate.de/asp/mycontent.asp" + location.search;
document.getElementsByTagName("head")[0].appendChild(s);
//-->
</script>
<script language="JavaScript" src=s >
</script>
</body>
</html>


thanx, jules

korkus2000

6:20 pm on Sep 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put the script block in the head of the page.

drofluga

6:56 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



I tried this. it still didnīt work.

document.write(s.src) gives the right link. It only wont load the script....

do you have any other ideas?

claus

7:02 pm on Sep 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.write('<script type="text\/javascript" src=');
document.write(s.src);
document.write('><\/script>');

Hope it helps
/claus

drofluga

7:20 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



thanx, this helped!

the error was:
by linking to thisPage.html?var1=1&var2=2 was in the address line: thisPage.html?var1=1%26var2=2 and it tried to load this.

does anybody know how to get the '&' sign in the address line instead of '%26'?

gph

10:18 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



alert(unescape('thisPage.html?var1=1%26var2=2'))

BjarneDM

6:06 am on Sep 10, 2003 (gmt 0)

10+ Year Member



as to avoiding the '&'-problem:
set your server up to use ';' instead of '&'.
solves *every* '&'-related problem in URLs