gesture="media" HTML 属性是什么?

What is the gesture="media" HTML attribute?

当使用 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" 值有什么作用?

media - 在媒体播放(即自动播放)上下文中将用户激活委托给 iframe。

这里有更多内容https://github.com/WICG/gesture-delegation/blob/master/explainer.md

这是一个非标准(或尚未标准)的东西,目前仅用于 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:

By default embedded IFrames will only be able to play muted or silent videos. However, if site owners wish for IFrames on their site to be able to play unmuted content, they may pass the autoplay permissions to the IFrame via the gesture=media attribute. This attribute allows any video contained in the IFrame to play as if it were hosted on the site.

这些东西都引用了 https://github.com/WICG/gesture-delegation/blob/master/explainer.md,但该文件的作者说 gesture 名称只是用作“占位符”,Chrome 发货意向将消失很快 HTML 标记属性的真实名称为 delegatestickyuseractivation。所以你需要做的是:

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