在没有 iframe 的情况下嵌入 HTML5 YouTube 视频? [英] Embed HTML5 YouTube video without iframe?

查看:20
本文介绍了在没有 iframe 的情况下嵌入 HTML5 YouTube 视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不使用 iframe 的情况下嵌入 html5 版本的 youtube 视频?

解决方案

这是一个没有 iFrame 的嵌入示例:

<div style="width: 560px; height: 315px; float: none; clear: both; margin: 2px auto;"><嵌入src="https://www.youtube.com/embed/J---aiyznGQ?autohide=1&autoplay=1"wmode="透明"类型=视频/mp4"宽度="100%" 高度="100%"允许=自动播放;加密媒体;画中画"允许全屏标题="键盘猫">

与常规 iframe 的嵌入"相比来自 YouTube 的代码:

<iframe宽度=560"高度=315"src="https://www.youtube.com/embed/J---aiyznGQ?autoplay=1"边框=0"允许=加速度计;自动播放;加密媒体;陀螺仪;画中画"允许全屏></iframe>

就 HTML5 而言,像这样使用 标签(更正):

<objectstyle="width: 820px; height: 461.25px; float: none; clear: both; margin: 2px auto;"data="http://www.youtube.com/embed/J---aiyznGQ?autoplay=1"></object>

Is it possible to embed an html5 version of a youtube video without using an iframe?

解决方案

Here is a example of embedding without an iFrame:

<div style="width: 560px; height: 315px; float: none; clear: both; margin: 2px auto;">
  <embed
    src="https://www.youtube.com/embed/J---aiyznGQ?autohide=1&autoplay=1"
    wmode="transparent"
    type="video/mp4"
    width="100%" height="100%"
    allow="autoplay; encrypted-media; picture-in-picture"
    allowfullscreen
    title="Keyboard Cat"
  >
</div>

compare to regular iframe "embed" code from YouTube:

<iframe
  width="560"
  height="315"
  src="https://www.youtube.com/embed/J---aiyznGQ?autoplay=1"
  frameborder="0"
  allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
  allowfullscreen>
</iframe>

and as far as HTML5 goes, use <object> tag like so (corrected):

<object
  style="width: 820px; height: 461.25px; float: none; clear: both; margin: 2px auto;"
  data="http://www.youtube.com/embed/J---aiyznGQ?autoplay=1">
</object>

这篇关于在没有 iframe 的情况下嵌入 HTML5 YouTube 视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆