Javascript 添加某些CSS样式';仅当在iframe或lightbox中查看站点时
每当在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;}
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
而不是您现在拥有的。