2012-05-11 36 views
1

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规则。谢谢!

回答

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; } 
相关问题