Forum Moderators: open
However, everyone seems to accidentally post the entire url (making the video unplayable). I was thinking if there's a way to strip out the first part of the url, the video could still play.
function stripURL(url)
{
if(url.indexOf('=')!= -1)
{
strip_start = url.lastIndexOf('=');
strip_end = url.length;
return url.substring(strip_start, strip_end);
}
else return url;
}
returns everything after the last '=' in the url (if there is one present).
I need to get this url:
[youtube.com...]
To change to this:
[youtube.com...]
Using little g's code:
---------------------------------
<head>
<script type="text/javascript">
var url = "http://www.youtube.com/watch?v=AAAAAAAAA";
var searchString = "?v=";
alert(url.substring(url.indexOf(searchString)+searchString.length));
</script>
</head>
<body>
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/ovJeGPeh43c"></param><embed src="http://www.youtube.com/v/http://www.youtube.com/watch?v=ovJeGPeh43c" type="application/x-shockwave-flash" width="425" height="350"></embed></object>
</body>
try this:
<body>
<script type="text/javascript">
var url = "http://www.youtube.com/v/http://www.youtube.com/watch?v=ovJeGPeh43c";
var searchString = "?v=";
var out = "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"></param><embed src=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"type=\"application/x-shockwave-flash\" width=\"425\" height=\"350\"></embed></object>";
document.write(out);
</script>
</body>
Andrew
[edited by: Little_G at 12:30 am (utc) on Sep. 10, 2006]
This is an example of the problem that is happening:
<body>
<script type="text/javascript">
var url = "http://www.youtube.com/v/[url ]http://www.youtube.com/watch?v=ovJeGPeh43c[ /url]";
var searchString = "?v=";
var out = "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"></param><embed src=\"http://www.youtube.com/v/";
out += url.substring(url.indexOf(searchString)+searchString.length);
out += "\"type=\"application/x-shockwave-flash\" width=\"425\" height=\"350\"></embed></object>";
document.write(out);
</script>
</body>