Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 添加某些CSS样式';仅当在iframe或lightbox中查看站点时_Javascript_Jquery_Html_Css_Iframe - Fatal编程技术网

Javascript 添加某些CSS样式';仅当在iframe或lightbox中查看站点时

Javascript 添加某些CSS样式';仅当在iframe或lightbox中查看站点时,javascript,jquery,html,css,iframe,Javascript,Jquery,Html,Css,Iframe,每当在iframe/lightbox中查看我的网站时,我想删除我的页眉/页脚。我在网上搜索了一下,找到了以下代码: if (window.top!=window.self) { // In a Frame or IFrame echo "<style> .sticky-wrapper{ display: none !important;} .header-contact-bar {display: none !important;}

每当在iframe/lightbox中查看我的网站时,我想删除我的页眉/页脚。我在网上搜索了一下,找到了以下代码:

if (window.top!=window.self)
    {
  // In a Frame or IFrame
echo "<style> 
         .sticky-wrapper{ display: none !important;} 
         .header-contact-bar {display: none !important;}
         #as.footer { display: none !important;}
      </style>";
    }
    else
    {
  // Not in a frame
    } 
if(window.top!=window.self)
{
//在帧或IFrame中
回声“
.sticky包装{显示:无!重要;}
.header联系人栏{显示:无!重要;}
#as.footer{display:none!important;}
";
}
其他的
{
//不在框架内
} 
CSS在lightbox中也会发生变化,但在我的网站上也会发生变化。问题是。我不明白为什么当我不在lightbox/iframe中时,它也会添加css

  • 我在用代码做什么

  • 代码能工作吗

  • 我是否必须在
    else
    语句中添加一些内容

  • 所以是的。什么


  • 经过一段时间的思考,我找到了自己的解决方案

    <script>
    
            if( self != top ) {
       headTag = document.getElementsByTagName("head")[0].innerHTML;
       var frameCSS = headTag + '<style type="text/css">.sticky-wrapper{ display: none !important;}  .header-contact-bar {display: none !important;} #as.footer { display: none !important;}</style>';
       document.getElementsByTagName('head')[0].innerHTML = frameCSS;
    }
      </script>
    
    
    如果(自我!=顶部){
    headTag=document.getElementsByTagName(“head”)[0].innerHTML;
    var frameCSS=headTag+'.粘性包装{display:none!important;}.页眉联系栏{display:none!important;}#as.footer{display:none!important;}';
    document.getElementsByTagName('head')[0].innerHTML=frameCSS;
    }
    
    你能分享你的网站吗url@Kyojimaru也许你可以使用
    window.location!=window.parent.location
    而不是您现在拥有的。