首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getElemenstByTag在facebook页面插件iframe中返回null

getElemenstByTag在facebook页面插件iframe中返回null
EN

Stack Overflow用户
提问于 2021-09-16 05:47:50
回答 1查看 51关注 0票数 2

代码中有没有什么错误?或者,我应该如何获得所需的输出?

我的目标是做到这一点

代码语言:javascript
复制
document.getElementById('iframe1').contentWindow.document.getElementsByTagName("IMG").style = "filter:invert(100%);";

完整的代码如下所示

代码语言:javascript
复制
<iframe onload="frameload()" lazy="true" sandbox="allow-same-origin allow-scripts block-popups allow-forms" class='viewport-iframe' id='iframe1' src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2FTroll.Malayalam%2Fposts%2F&tabs=timeline&width=340&height=500&small_header=true&adapt_container_width=true&colorscheme=&hide_cover=false&show_facepile=false&appId" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share" frameborder="0" allowFullScreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe> 
<script type="text/javascript">
  function frameload(){
   alert(document.getElementById('iframe1'));
   alert(document.getElementById('iframe1').getElementsByTagName("img"));
  }
</script>
EN

回答 1

Stack Overflow用户

发布于 2021-09-16 06:06:09

如果你成功地获得了iframe,那么就像这样修改你的代码。在iframe标签中添加属性

代码语言:javascript
复制
<iframe onload="frameload()" id='iframe1'></iframe> 
<script type="text/javascript">
   function frameload(){
         var tags = [...document.getElementById('iframe1').contentWindow.document.getElementsByTagName("img")];
         tags.forEach((el)=>{el.style="filter:invert(100%);"});
    }
</script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69202933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档