Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html : iframe not showing content in html

Tags:

html

xhtml

iframe

I want to show a youtube video in html 4. For that, I am using iframe. But the content of iframe is not showing.

<iframe frameborder="1" width="420" height="345" src="https://www.youtube.com/watch?v=C8kSrkz8Hz8"></iframe>

FYI: I am using Firefox 29.0 and Chrome 35.0. Both browsers are showing the same result.

like image 408
Joydev Pal Avatar asked Jun 14 '14 15:06

Joydev Pal


2 Answers

When you try to put the whole YouTube page into an iframe, it sends a HTTP header called X-Frame-Options with the SAMEORIGIN value, which tells the browser, that the page can only be displayed in a frame on the same origin as the page itself.

You should use the provided embed code (you can find it below every YouTube video), which is also an iframe, but with a different URL. It will only show the player.

In this case, the embed code would be:

<iframe width="560" height="315" src="//www.youtube.com/embed/C8kSrkz8Hz8" frameborder="0" allowfullscreen></iframe> 
like image 51
user Avatar answered Sep 21 '22 04:09

user


Change your src with //www.youtube.com/embed/C8kSrkz8Hz8

your code shoud look like this

<iframe frameborder="1" width="420" height="345" src="//www.youtube.com/embed/C8kSrkz8Hz8"></iframe> 

Find code under each video on youtoube at Share menu.

like image 21
user3718552 Avatar answered Sep 21 '22 04:09

user3718552