View Full Version : Can't change scripts source dynamically

09-24-2011, 12:49 AM

I try to change script source dynamically.

When I use the following code, it works fine, and the script is executed

<script type="text/javascript">
document.write('<script src="http://gamestoenjoy.com/site/test.php"');

However when I use the following code, it doesn't work, the script isn't executed

<script type="text/javascript">
var url = "http://gamestoenjoy.com/site/test.php";
document.write('<script src=url>');

The only difference between the codes is that in the first code I use constant sting, and in the second code I use variable, in order to make the source dynamic.

Please help me to solve this problem.

09-24-2011, 01:08 AM
this is a string:
document.write('<script src=url>');

and the code doesn't know that you are trying to pass a variable

you need something like this:
document.write('<script src='+url+'>');

not that I'm guaranteeing that it will work...

09-24-2011, 08:09 AM
Thanks a lot, it worked :)