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

推荐订阅源

W
WeLiveSecurity
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
Cloudbric
Cloudbric
The Register - Security
The Register - Security
小众软件
小众软件
PCI Perspectives
PCI Perspectives
G
Google Developers Blog
AI
AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
TaoSecurity Blog
TaoSecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
F
Full Disclosure
N
Netflix TechBlog - Medium
博客园_首页
Last Week in AI
Last Week in AI
A
Arctic Wolf
B
Blog RSS Feed
J
Java Code Geeks
C
Cybersecurity and Infrastructure Security Agency CISA
I
InfoQ
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
NISL@THU
NISL@THU
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
有赞技术团队
有赞技术团队
S
Schneier on Security
L
Lohrmann on Cybersecurity
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Security Latest
Security Latest
Vercel News
Vercel News
博客园 - 司徒正美
Webroot Blog
Webroot Blog
Hacker News: Ask HN
Hacker News: Ask HN
A
About on SuperTechFans

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

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