【发布时间】:2021-11-11 02:56:06
【问题描述】:
代码中是否有任何错误?或者我应该如何获得想要的输出?
我的目标是这样做
document.getElementById('iframe1').contentWindow.document.getElementsByTagName("IMG").style = "filter:invert(100%);";
下面给出了完整的代码
<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>
【问题讨论】:
-
如果你想用
document.getElementById('iframe1').contentWindow.document.getElementsByTagName("IMG"),那你为什么叫document.getElementById('iframe1').getElementsByTagName("img")? -
@VLAZ 我正在尝试对代码进行不同类型的更改
-
@VLAZ 哪个是正确的?
-
您无法访问从其他域加载其内容的 iframe,并从您的页面编写脚本,同源策略可以防止这种情况发生。
-
@CBroe 有什么方法可以让 IFRAME 中的所有图像都反转颜色
标签: javascript html css facebook iframe