1

Im trying to add youtube video in my webpage using below mentioned code, is there anyone who can help me with that.? have a look on my code below.

 <div style="width:400px; height:200px;">
   <embed src="https://www.youtube.com/watch?v=Q-AV9KMLTFc" wmode="transparent" 
type="application/x-shockwave-flash" width="100%" height="100%" 
allowfullscreen="true" title="Adobe Flash Player">
 </div>
Samar
  • 67
  • 1
  • 8
  • you might want to check [W3](https://www.w3schools.com/html/html_youtube.asp) – Hash Jun 28 '17 at 11:42
  • Taken into note, If you find a specific answer provided below helpful the most, do not forget to [mark] that answer accepted. Vote up either of the answers if you think that they are helpful to you – User 328 6227 Jun 28 '17 at 13:13
  • hmm im on it and will surely post here if i found something ease to use. – Samar Jun 29 '17 at 11:44

2 Answers2

0

Use the code that Youtube generates for you after clicking share > embed. It looks like this:

<iframe width="560" height="315" src="https://www.youtube.com/embed/Q-AV9KMLTFc" frameborder="0" allowfullscreen></iframe>

Set width and height to whatever values you like.

Ondra Koupil
  • 903
  • 5
  • 8
  • Actually the problem is i can't use embed code, users will be posting their video by youtube link's not embed code. – Samar Jun 29 '17 at 11:41
  • That's also possible. In the youtube link, there is video's ID code that goes after "v=". For instance, in https://www.youtube.com/watch?v=w8lH8tNlAXc the code is w8lH8tNlAXc. See https://stackoverflow.com/questions/3452546/javascript-regex-how-do-i-get-the-youtube-video-id-from-a-url for more. That ID code is also in the embed code generated by Youtube. If you change the ID code in embed code, the video also changes. So you'll just need to parse the link that user pasted, grab the ID code and put it into the Youtube's basic embed code. – Ondra Koupil Jul 03 '17 at 07:58
0

You could do it with <iframe> like this:

<iframe width="500" height="500"
src="https://www.youtube.com/embed/vEROU2XtPR8">
</iframe>

With Autoplay:

<iframe width="500" height="500"
src="https://www.youtube.com/embed/vEROU2XtPR8?autoplay=1">
</iframe>

Note: After "embed/" in src, be sure to write the correct youtube video id which can be found in the URL link after "=" symbol.

Ex: In this link, https://www.youtube.com/watch?v=vEROU2XtPR8 Youtube video id="vEROU2XtPR8".

Be sure to give the width and height properties of the video size that should be displayed on the screen.

  • your're right Soundharya but the problem is i dont wanna use Embed code, becuase user will directly paste their video link not embed code. so if there is any way to use youtube video without the embed code please share with us here. – Samar Jun 29 '17 at 11:39