0

I try to get a URL of a YouTube-video from database and embed it in a page.

I get the "An error occured. Please try again later" message. Pls help! :(

String in the DB: https://www.youtube.com/watch?v=JjFsNSoDZK8

HTML code (inside a table):

<tr><td colspan=3><iframe id='Trailer' width="640" height="360" src="" frameborder="0" allowfullscreen></iframe></td></tr>

JS code (jQuery):

$("#MovieDetails").find("#Trailer").attr('src',arr['Trailer'].replace("youtube.com/","youtube.com/embed/") + "?feature=player_detailpage");

(Here, MovieDetails is the id of the table); Also, that string at the end: "?feature=player_detailpage", even without it is not working.

Tried several ways to change the URL-string but cannot seem to find the right one. Same mistake always.

EDIT: If I use the code from YouTube (that it gives you in movie info -> share -> embed) and hardcode it in my page, it works.

Geri
  • 7
  • 3

3 Answers3

0

I see a couple things wrong:

  1. //www.youtube.com/embed/JjFsNSoDZK8 Not the url with the id as a the value of v get parameter; like the link you have in your post (https://www.youtube.com/watch?v=JjFsNSoDZK8)

  2. When you replace the url you are adding the param with ? i think it should be & since the query string already exists, i don't think it matters though because http://www.youtube.com/embed/JjFsNSoDZK8 is the correct url according to the embed tab on youtube


url = 'https://www.youtube.com/watch?v=JjFsNSoDZK8';
url.replace('youtube.com/', 'youtube.com/embed/') + "?feature=player_detailpage"
// "https://www.youtube.com/embed/watch?v=JjFsNSoDZK8?feature=player_detailpage"
dm03514
  • 54,664
  • 18
  • 108
  • 145
0

Assuming that arr['Trailer'] == "https://www.youtube.com/watch?v=JjFsNSoDZK8"

Try to change your replace to the following:

arr['Trailer'].replace("https://www.youtube.com/watch?v=", "//www.youtube.com/embed/");

jsFiddle - http://jsfiddle.net/WFd79/

mara-mfa
  • 895
  • 6
  • 9
  • Thanks for the answers! :) Here's what I finally did: put in the DB the link that YouTube->VideoInfo->Share->Embed gives you as src inside the iframe-tag. Now I can place it in the table without having to furtherly edit it. – Geri Jul 25 '13 at 02:30
0

Try to replace "https://www.youtube.com/watch?v=" to "//www.youtube.com/embed/" then it will work.

vikash
  • 1
  • 2