如果在弹出窗口中打开页面,如何隐藏元素

时间:2012-05-11 15:53:01

标签: javascript jquery css

的jQuery

$('a.popup').click(function(){
    window.open( this.href, 'Page title', 'width=600, height=650' );
    return false;
});

HTML

<a class="popup" href="sample.html">

如果在弹出窗口中打开我的sample.html页面,我想隐藏页眉和页脚。我可以将类名添加到弹出窗口的<html><body>吗?所以我可以添加CSS规则。谢谢!

1 个答案:

答案 0 :(得分:3)

来自sample.html部分的<head>,只检查window.opener是否存在,例如

<script>
   if (window.opener) {
      /* i'm a popup, add "popup" class to <html> element */
      document.documentElement.className += " popup";
   }
</script>

然后您可以使用类.popup设置自己的CSS样式,例如

header { display: block; }
.popup header { display: none; }