I’ve looked through all the stuff to remove characters from strings but I don’t understand what’s going on here.
I’m using a jQuery script to get videos from a Youtube channel and it displays them with links to the video. On the same page I’ve embedded a video using the iframe code. I set the videos to open in the target which is the iframe. However the URLs don’t work.
- URL it should be: http:// http://www.youtube.com/embed/VIDEO_ID
- URL it currently is: http:// http://www.youtube.com/watch?v=VIDEO_ID&feature=youtube_gdata
(Broken links because new users can’t post more than 2 links)
I need to remove the extra so what I wanted to do was remove http://www.youtube.com/watch?v= from the start and &feature=youtube_gdata from the end then add http://www.youtube.com/embed/ back to the start.
However the link seems to be some sort of event and I just couldn’t work out how to do it.
+ e.link[0].href +
The above is how the link appears in the javascript.
How can I make the link I need from this?
Thanks very much,
Jack Clarke
You can get the video id out of the old URL and construct a new URL like this:
Working example: http://jsfiddle.net/jfriend00/zwcgL/.
Using this technique of extracting the actual video ID from the original URL, you can then construct any type of other URL that uses it with some simple string addition.