隐藏从iframe加载的任何内容或元素

Hide any contents or elements loading from an iframe

本文关键字:元素 任何内 iframe 加载 隐藏      更新时间:2023-09-26

例如:试图通过隐藏类来隐藏wiki徽标(与wiki徽标关联的"#central featured徽标"(,但不起作用

<script>
    $(document).ready(function () {
 try {
       if(window.name != "") 
       {
         document.getElementById("#central-featured-logo").style.display ='none';
       }   
     }  
    catch (e) { alert("Error:  " + e); }
});
</script>
<iframe  width="100%" height="400" src="https://www.wikipedia.org/"></iframe>

您不应该将hashtag传递给document.getElementByIdcentral-featured-logo似乎也是一个类,而不是一个ID,所以您应该使用document.getElementsByClassName

$(document).ready(function () {
 try {
       if(window.name != "") 
       {
         document.getElementsByClassName("central-featured-logo")[0].style.display ='none';
       }   
     }  
    catch (e) { alert("Error:  " + e); }
});