“gesture = media” HTML属性是什么?

3
当使用oembed获取Youtube的嵌入代码时,我得到了以下HTML代码:
<iframe allowfullscreen="" frameborder="0" gesture="media" height="270" src="https://www.youtube.com/embed/4B36Lr0Unp4?feature=oembed" width="480"></iframe>

你是否注意到了 gesture="media" HTML 属性?它是什么?"media" 值是什么作用?

2个回答

3

这是一种非标准(或尚未标准化)的技术,目前仅在Chrome浏览器中用于媒体自动播放。

请参见https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#iframe

Iframe delegation

Once an origin has received autoplay permission, it can delegate that permission to iframes via a new HTML attribute. Check out the Gesture Delegation API proposal to learn more.

<iframe src="myvideo.html" gesture="media">

Without iframe delegation, videos will not be able to autoplay with sound.

请参考https://www.chromium.org/audio-video/autoplay

默认情况下,嵌入的IFrames只能播放静音视频。然而,如果网站所有者希望其网站上的IFrames能够播放未静音的内容,则可以通过gesture=media属性将自动播放权限传递给IFrame。此属性允许IFrame中包含的任何视频以与托管在该网站上相同的方式播放。

这两个链接都引用了https://github.com/WICG/gesture-delegation/blob/master/explainer.md,但该文档的作者表示gesture名称仅作为“占位符”使用,并且Chrome意图很快会发布真正的HTML标记属性名称delegatestickyuseractivation。因此,您需要执行以下操作:

<iframe src="myvideo.html" delegatestickyuseractivation="media">

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接