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

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
V
Visual Studio Blog
有赞技术团队
有赞技术团队
U
Unit 42
D
Docker
小众软件
小众软件
F
Full Disclosure
I
Intezer
Scott Helme
Scott Helme
P
Privacy International News Feed
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
B
Blog
Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
宝玉的分享
宝玉的分享
S
Security Affairs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
Schneier on Security
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Threat Research - Cisco Blogs
量子位
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Heimdal Security Blog
N
Netflix TechBlog - Medium
H
Hacker News: Front Page
P
Proofpoint News Feed
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
S
Schneier on Security

博客园 - 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(); 
   }
}

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