惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
Scott Helme
Scott Helme
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
J
Java Code Geeks
U
Unit 42
The GitHub Blog
The GitHub Blog
H
Help Net Security
T
Tenable Blog
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
L
Lohrmann on Cybersecurity
T
Threatpost
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
L
LINUX DO - 最新话题
K
Kaspersky official blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threat Research - Cisco Blogs
C
Check Point Blog
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
Y
Y Combinator Blog
N
News | PayPal Newsroom
M
MIT News - Artificial intelligence
Latest news
Latest news
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
I
Intezer
爱范儿
爱范儿
F
Fortinet All Blogs
P
Palo Alto Networks Blog
C
CERT Recently Published Vulnerability Notes

博客园 - Valens

IIS无法启动:存储空间不足解决办法 做程序员的,平时眼睛总对着代码,很累!看看美女放松放松哦! - Valens - 博客园 How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA Mark:使用线程处理(C# 编程指南) 交集:通过使用默认的相等比较器对值进行比较生成两个序列的交集 LINQ to SQL StepByStep (1) 就事网上线了 About .net Format 【技巧】asp的找不到文件的问题 【翻译】Visual Studio Smart Tag Expansion 小技巧 【翻译】使用ASP.NET 2.0记录错误 ListView提示和技巧 独有数据绑定控件ListView LINQ的标准查询操作符 轻松Web调试、扩展Reflector及更多内容 构建不带Web窗体的Web应用程序_ASP.NET MVC ASP.NET 应用程序的扩展策略 单页界面和AJAX模式 删除Visual Studio IDE最近打开文件和项目列表
【翻译】父窗口关闭的时候子窗口也同时关闭 - Valens - 博客园
Valens · 2008-07-08 · via 博客园 - Valens

【翻译】父窗口关闭的时候子窗口也同时关闭

2008-07-08 13:19  Valens  阅读(644)  评论()    收藏  举报

如何当父窗口关闭的时候子窗口也同时关闭呢?假如我是网站的使用者,我倒是不想父窗口关闭时会自动关闭所有的子窗口,因此我觉得上面的这个需求是奇怪的。

下面就是可以实现如标题所描述的代码。我想确保的是我所有已经打开的窗口之间的联系,然后当父窗口被关闭的时候,简单地使用一个循环这些子窗口,并关闭它们。

在父窗口的 body 标签内添加 "onunload" 事件。请注意当页面被刷新的时候会引发该事件。

<body onunload="closeChildWindows()"><href="#" onclick="openWindow('Pop1.aspx','Pop1')">Open Window 1</a>
    
    
<href="#" onclick="openWindow('Pop2.aspx','Pop2')">Open Window 2</a>


<script language="javascript" type="text/javascript">// create an array of child windows 
var childWindows = new Array(); function openWindow(url,name) 
{
   newWindow 
= window.open(url,name,'width=100,height=100;dependent=yes');
   
// add the new child window in the collection
   childWindows.push(newWindow); 
     
}
function closeChildWindows() 
{
    
    
if(!sure) return// iterate through the collection and close all the windows  
   
   
for(i=0; i<childWindows.length; i++
   {
       childWindows[i].close(); 
   }
}

你还可以使用一个确认框来确定是否要关闭子窗口。提醒用户所有他/她可以选择是否将打开的子窗口都被关闭。