admin管理员组文章数量:1391947
I'm using codes like this in my blog:
<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>
And my question is simple, how can I automatically add allowfullscreen
to every new iframe using javascript/jQuery?
Also, I presume the script should identify if there's the tag allowfullscreen
added already.
I couldn't find a solution anywhere else.
I'm using codes like this in my blog:
<iframe width="560" height="315" src="https://www.youtube-nocookie./embed/0eBDVy5nihM?rel=0" frameborder="0" allowfullscreen></iframe>
And my question is simple, how can I automatically add allowfullscreen
to every new iframe using javascript/jQuery?
Also, I presume the script should identify if there's the tag allowfullscreen
added already.
I couldn't find a solution anywhere else.
Share Improve this question edited Jul 24, 2017 at 17:44 Govind Samrow 10.2k14 gold badges59 silver badges90 bronze badges asked Jul 24, 2017 at 17:42 user013314user013314 1171 silver badge3 bronze badges 1- How are you creating the iframes currently? – Heretic Monkey Commented Jul 24, 2017 at 17:57
2 Answers
Reset to default 4Should be just this:
$('iframe').attr('allowFullScreen', '');
There is no need to check for allready set allowfullscreen
as there will be no error if it is.
From here: https://stackoverflow./a/3774041/3764994 and here: Set IFrame allowfullscreen with javascript
To get all the iframe elements use getElementsByTagName(), then iterate over those with a for loop:
Something like this:
var i, frames;
frames = document.getElementsByTagName("iframe");
for (i = 0; i < frames.length; ++i)
{
// The iFrame
if (!frames[i].hasAttribute("allowfullscreen")) {
frames[i].setAttribute('allowFullScreen', '')
}
}
本文标签: javascriptHow can I automatically add allowfullscreen to every new iframeStack Overflow
版权声明:本文标题:javascript - How can I automatically add allowfullscreen to every new iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744685032a2619645.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论