...

View Full Version : Javascript retrieve url



embeebutterly
12-11-2011, 10:44 PM
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?host=brittv-103&stream=skynews.stream_360p


<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



<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




<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

embeebutterly
12-12-2011, 01:31 PM
Please guys, any help with this?

Thanks

Old Pedant
12-12-2011, 09:18 PM
No idea why it wouldn't work. Can you show this on a live page? Give us a URL to look at?

embeebutterly
12-12-2011, 09:33 PM
sure, the link is up top, or here (http://www.brittv.co.uk/template.php?host=brittv-103&stream=skynews.stream_360p) Thanks!

Old Pedant
12-12-2011, 09:48 PM
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

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!


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:


<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.

Old Pedant
12-12-2011, 09:49 PM
And sorry about being blind. It goes with the senility.

embeebutterly
12-12-2011, 10:15 PM
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!

Old Pedant
12-12-2011, 10:26 PM
You *LEFT IN* this completely and utterly bogus line!!!


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.

embeebutterly
12-12-2011, 10:37 PM
sorry, i did! Nice one Old Pedant (http://www.codingforums.com/member.php?u=72271) it seems to be working now, just got to make sure i get the servers right!

Will post back final result



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum