如何解决“允许属性优先于allowfullscreen”警告?

And*_*sen 7 javascript iframe cross-browser

Allow attribute will take precedence over 'allowfullscreen'.

我收到此警告消息是因为我添加了一个 iframe 和allow="fullscreen" and allowfullscreen.

allow根据https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe,它似乎不适用于 IE、Edge 或 Firefox 。

如何以跨浏览器兼容的方式解决/消除此警告消息?

这是在 Chrome 中重现警告消息的最小片段:

const iframe = document.createElement('iframe');
iframe.setAttribute('allowFullScreen', '');
iframe.setAttribute('allow', 'fullscreen');
Run Code Online (Sandbox Code Playgroud)

And*_*sen 6

事实证明,交换这些setAttribute行的顺序会使警告静音:

const iframe = document.createElement('iframe');
iframe.setAttribute('allow', 'fullscreen'); // must be 1st
iframe.setAttribute('allowFullScreen', '');
Run Code Online (Sandbox Code Playgroud)


Nic*_*ier 6

在 Vimeo 嵌入 iFrame 上,allowFullScreen完全删除。

<div class="embed-responsive embed-responsive-16by9"><iframe src="https://player.vimeo.com/video/000000000" allow="autoplay; fullscreen" allowfullscreen></iframe></div>
Run Code Online (Sandbox Code Playgroud)

<div class="embed-responsive embed-responsive-16by9"><iframe src="https://player.vimeo.com/video/000000000" allow="autoplay; fullscreen"></iframe></div>
Run Code Online (Sandbox Code Playgroud)

  • 我们已更新 Vimeo.com 上的嵌入代码生成,仅包含允许属性,因此在使用更新嵌入代码时您不应再看到警告。如果您有现有的嵌入内容,并且您的目标浏览器不需要,则可以删除 allowedfullscreen 属性。 (2认同)