添加特定的CSS样式's仅当网站在iframe或lightbox中查看时
Add certain CSS style's ONLY when the site is viewed in an iframe or lightbox
每当我的网站在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
}
CSS在灯箱中也改变了,但在我的网站上也改变了。问题是。我不明白为什么它也添加css当我不在lightbox/iframe
我做了什么错误的代码?
代码工作吗?
我必须在
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>
相关文章:
- 什么更好?使用iframe或jQuery之类的东西在外部网站中加载HTML文件
- 如何使用JS/jQuery在另一个网站上显示iframe中的特定内容
- 代理一个网站能够在iframe中进行所见即所得编辑-它是如何工作的
- 在iframe中阻止网站中的vimeo自动播放
- 按下按钮时弹出iframe或网站
- 将网站与 iframe 重叠
- 更改网站上所有 iFrame 的 iFrame 尺寸
- 防止iframe破坏会杀死网站上的所有链接
- 在桌面视图的iframe中加载网站
- 调整外部网站内容的大小以适应iFrame宽度
- 如何在谷歌网站中显示与iframe中的特定人员共享的谷歌云端硬盘html链接
- 我如何知道网站是否接受 iframe
- 网站中的可疑 iFrame
- 隐藏滚动条 iFrame 子网站
- 如果网站在框架/ iframe内,则document.referer将始终包含一个值
- 如果我的网站在iframe中,我不希望标题显示在任何页面中
- 在我们的网站和iframe中禁用Flash
- 禁止全能 S.t() 调用在使用 iframe 的网站中生成“第二次”网页浏览
- 在后台加载iframe网站
- 访问iframe网站