Welcome to WebmasterWorld Guest from 18.206.194.83

Forum Moderators: open

Message Too Old, No Replies

load javascript from variable

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

New User

10+ Year Member

joined:Sept 8, 2003
posts:4
votes: 0


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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


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

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

New User

10+ Year Member

joined:Sept 8, 2003
posts:4
votes: 0


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
6:20 pm on Sept 8, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


Put the script block in the head of the page.
6:56 pm on Sept 8, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 8, 2003
posts:4
votes: 0


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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 15, 2003
posts:2412
votes: 5


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

Hope it helps
/claus

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

New User

10+ Year Member

joined:Sept 8, 2003
posts:4
votes: 0


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 Sept 8, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Jan 31, 2002
posts:285
votes: 0


alert(unescape('thisPage.html?var1=1%26var2=2'))
6:06 am on Sept 10, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Dec 22, 2002
posts:334
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members