html : iframe 没有在 html 中显示内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24221580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html : iframe not showing content in html
提问by Joydev Pal
I want to show youtube video in html 4. For that i am using iframe. But the content of iframe is not showing.
我想在 html 4 中显示 youtube 视频。为此我使用 iframe。但是 iframe 的内容没有显示。
<iframe frameborder="1" width="420" height="345" src="https://www.youtube.com/watch?v=C8kSrkz8Hz8"></iframe>
I am using Firefox 29.0 and Chrome 35.0. Both of the browsers are showing the same result.
我使用的是 Firefox 29.0 和 Chrome 35.0。两个浏览器都显示相同的结果。
回答by user3718552
Change your src with //www.youtube.com/embed/C8kSrkz8Hz8
更改您的 src //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.
在 Youtoube 上的“共享”菜单中的每个视频下查找代码。
回答by user
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.
当您尝试将整个 YouTube 页面放入 iframe 时,它会发送一个X-Frame-Options
带有该SAMEORIGIN
值的 HTTP 标头,该标头告诉浏览器该页面只能显示在与页面本身具有相同来源的框架中。
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.
您应该使用提供的嵌入代码(您可以在每个 YouTube 视频下方找到它),它也是一个 iframe,但具有不同的 URL。它只会显示播放器。
In this case, the embed code would be:
在这种情况下,嵌入代码将是:
<iframe width="560" height="315" src="//www.youtube.com/embed/C8kSrkz8Hz8" frameborder="0" allowfullscreen></iframe>
回答by tracyak13
You should change the youtube URL to remove the "s" so it looks like this:
您应该更改 youtube 网址以删除“s”,使其看起来像这样:
<iframe width="420" height="345" src="//www.youtube.com/embed/C8kSrkz8Hz8" frameborder="1" allowfullscreen></iframe>
You should also be able to embed a youtube video from the page. Please see the screenshot attached:
您还应该能够从页面嵌入 YouTube 视频。请看附上的截图:
回答by chandu
replace you Iframe with this one. this works for you.
用这个替换你的 Iframe。这对你有用。
<iframe width="640" height="390" src="//www.youtube.com/embed/C8kSrkz8Hz8" frameborder="0" allowfullscreen></iframe>
missing attributes
are: frameborder="0"
, allowfullscreen
缺少的attributes
是:frameborder="0"
, allowfullscreen