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 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    84
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question Javascript retrieve url

    Hi guys, i need to retrieve the url created in the following script and embed it in the player below. Here is what i have. You can see how it works (and doesn't) here http://www.brittv.co.uk/template.php...ws.stream_360p

    Code:
    <html>
    <head>
    <title>...</title>
    
    
    <?php
    $URL_GETKEY="http://www.uktvlive.com/tvc/key.php";
    
    function doCurl($url)
    {
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $output = curl_exec($ch);       
            curl_close($ch);
            return $output;
    }
    
    
    $a=doCurl($URL_GETKEY);
    $split=explode("<split>",$a);
    
    ?>
    
    
    <script type="text/javascript">
    // parse the querystring and create a dictionary of terms for later use:
    var qs = [ ]; // where the dictionary goes
    
    if ( location.search.length > 1 )
    {
        var pairs = location.search.substring(1).split("&");
        for ( var p = 0; p < pairs.length; ++p )
        {
            var pair = pairs[p].split("=");
            qs[pair[0]] = unescape( pair[1] );
        }
    }
    
    // do the replacements *after* page is loaded, for simplicity:
    function doReplacements( )
    {
        
    
        var link = document.getElementById("link1");
        link.href = "rtsp://81.104.67.230/"+ qs["host"] + "/" + qs["stream"] + "?userID=" + "<?php echo $split[5];?>"  + "&accessKey=" + "<?php echo $split[6];?>" + "&sdp=alt&device=mobile";
        link.innerHTML = qs["page"];
    
        // and of course you could do any other replacements, too.
    } 
    window.onload = doReplacements;  
    </script>
    </head>

    The following part produces the url


    Code:
    <body>
    
    <br/><br/>
    <a id="link1">Generic Link</a>
    <br/><br/>

    Lastly we have the player embed code, this is where im stuck im afraid



    Code:
    <script type="text/javascript">
    var url = qs["link1"]; // or whatever name it was passed by
    
    document.write('<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '
        + ' WIDTH="300" HEIGHT="160" '
        + ' CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">\n'
        + '<PARAM name="SRC" VALUE = "http://www.tvpc.com/images/image1.gif" >\n'
        + '<PARAM name="QTSRC" VALUE = "' + url +'" >\n'
        + '<PARAM name="HREF" VALUE = "' + url + '" >\n'
        + '<PARAM name="AUTOPLAY" VALUE = "true" >\n'
        + '<PARAM name="CONTROLLER" VALUE = "true" >\n'
        + '<PARAM name="TYPE" VALUE = "video/quicktime" >\n'
        + '<PARAM name="TARGET" VALUE = "myself" >\n'
        + '<EMBED \n'
        + ' SRC = "#" \n'
        + ' QTSRC = "' + url + '" \n'
        + ' HREF = "' + url + '" \n'
        + ' TARGET = "myself"\n'
        + ' CONTROLLER = "true"\n'
        + ' WIDTH = "300" \n'
        + ' HEIGHT = "160" \n'
        + ' LOOP = "false" \n'
        + ' AUTOPLAY = "true" \n'
        + ' PLUGIN = "quicktimeplugin" \n'
        + ' TYPE = "video/quicktime" \n'
        + ' CACHE = "false" \n'
        + ' PLUGINSPAGE= "http://www.apple.com/quicktime/download/" >\n'
        + '</EMBED>\n'
        + '</OBJECT>\n'
    );
    </script>
    
    
    
    </body>
    </head>

    Thanks in advance guys

  • #2
    New Coder
    Join Date
    Jan 2011
    Posts
    84
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Please guys, any help with this?

    Thanks

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,051
    Thanks
    80
    Thanked 4,550 Times in 4,514 Posts
    No idea why it wouldn't work. Can you show this on a live page? Give us a URL to look at?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Jan 2011
    Posts
    84
    Thanks
    9
    Thanked 0 Times in 0 Posts
    sure, the link is up top, or here Thanks!

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,051
    Thanks
    80
    Thanked 4,550 Times in 4,514 Posts
    But you aren't passing in any link1=xxxx in the querystring! Did you expect it to appear by magic in the qs[ ] array?

    You do
    Code:
    var url = qs["link1"]; // or whatever name it was passed by
    but it is not "passed" by ANY name whatsoever!

    You don't want that code.

    You want to get the url from the link that is right there on that page!
    Code:
    var url = document.getElementById("link1").href;
    BUT!

    So the better solution is to create that URL as soon as you have parsed the query string and then use it both places:
    Code:
    <script type="text/javascript">
    // parse the querystring and create a dictionary of terms for later use:
    var qs = [ ]; // where the dictionary goes
    
    if ( location.search.length > 1 )
    {
        var pairs = location.search.substring(1).split("&");
        for ( var p = 0; p < pairs.length; ++p )
        {
            var pair = pairs[p].split("=");
            qs[pair[0]] = unescape( pair[1] );
        }
    }
    // get the url now, for both usages on the page:
    var url = "rtsp://81.104.67.230/"+ qs["host"] + "/" + qs["stream"] 
            + "?userID=<?php echo $split[5];?>&accessKey=<?php echo $split[6];?>&sdp=alt&device=mobile";
    
    // do the replacements *after* page is loaded, for simplicity:
    function doReplacements( )
    {
        var link = document.getElementById("link1");
        link.href = url;    
        link.innerHTML = qs["page"];
    
        // and of course you could do any other replacements, too.
    } 
    window.onload = doReplacements;  
    </script>
    And then just use that same url variable when doing the document.write.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,051
    Thanks
    80
    Thanked 4,550 Times in 4,514 Posts
    And sorry about being blind. It goes with the senility.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Jan 2011
    Posts
    84
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Mate im sorry but im not getting anywhere with this, the page is there with the new code but now there is no url at all.

    Sorry, im doing my best to get my head around it!

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,051
    Thanks
    80
    Thanked 4,550 Times in 4,514 Posts
    You *LEFT IN* this completely and utterly bogus line!!!
    Code:
    var url = qs["link1"]; // or whatever name it was passed by
    I told you that you can *NOT* try to get qs["link1"] if there is not "link1" in the query string!

    REMOVE THAT LINE.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New Coder
    Join Date
    Jan 2011
    Posts
    84
    Thanks
    9
    Thanked 0 Times in 0 Posts
    sorry, i did! Nice one Old Pedant it seems to be working now, just got to make sure i get the servers right!

    Will post back final result


  •  

    Posting Permissions

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