Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Can't change scripts source dynamically

    Hi,

    I try to change script source dynamically.

    When I use the following code, it works fine, and the script is executed
    Code:
    <script type="text/javascript">
    document.write('<script src="http://gamestoenjoy.com/site/test.php"');
    </script>
    However when I use the following code, it doesn't work, the script isn't executed
    Code:
    <script type="text/javascript">
    var url = "http://gamestoenjoy.com/site/test.php";
    document.write('<script src=url>');
    </script>
    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.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,984
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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...

  • Users who have thanked xelawho for this post:

    gamestoenjoy (09-24-2011)

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks a lot, it worked


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •