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)
事实证明,交换这些setAttribute行的顺序会使警告静音:
const iframe = document.createElement('iframe');
iframe.setAttribute('allow', 'fullscreen'); // must be 1st
iframe.setAttribute('allowFullScreen', '');
Run Code Online (Sandbox Code Playgroud)
在 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)