www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] document.write to write a script

  1. #1
    Join Date
    Sep 2012
    Location
    Houston, TX
    Posts
    4

    resolved [RESOLVED] document.write to write a script

    Im trying to dynamicly change the src of this script

    Code:
    <script 
        type="text/javascript" 
        src="https://api.twitch.tv/kraken/streams?game=DayZ&limit=4&offset=0&callback=showGame">
    </script>
    But ive been googling it and cant seem to find the proper syntex to write it dynamically.. i haven't even started using the variable... just trying to get the syntex to write it first... the ultimate goal will be to change the offset value inside the src

    this is what I found browsing the web but it does not work

    Code:
    <script>
    document.write("<script type="text/javascript" src="https://api.twitch.tv/kraken/streams?game=DayZ&limit=4&offset=0&callback=showGame<\/script>");
    </script>
    is it a syntax issue or am i taking the completely wrong approach?

    If this did work i was going to go with something like

    Code:
    <script>
    var variable = (source for my variable)
    document.write("<script type="text/javascript" src="https://api.twitch.tv/kraken/streams?game=DayZ&limit=4&offset=" + variable + "&callback=showGame<\/script>");
    </script>

  2. #2
    Join Date
    Nov 2010
    Posts
    1,043
    it depends on what else you are trying to do. This can work:
    Code:
    <script id="myscript" type="text/javascript" src="https://api.twitch.tv/kraken/streams?game=DayZ&limit=4&offset=0&callback=showGame"></script>
    <script type = "text/javascript">
    var variable=7;
    document.getElementByID("myscript").src="https://api.twitch.tv/kraken/streams?game=DayZ&limit=4&offset=" + variable + "&callback=showGame";
    </script>
    or you might have to get sneakier and try this:
    Code:
    <script type="text/javascript">
    var variable=7;
    document.write(
          '<sc' + 'ript type="text/javascript" '
        + ' src="https://api.twitch.tv/kraken/streams?game=DayZ&limit=4&offset=' + variable + '&callback=showGame">'
        + '</sc' + 'ript>');
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles