---
title: "关闭浏览器的js"
author: "ldz0414"
date: "2011-02-28T10:43:45Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2011-02-28T10:43:45Z"
id: 933175
url: "https://0414.iteye.com/blog/933175"
---

本文参考：<http://www.cnblogs.com/zgqys1980/archive/2009/05/19/1460254.html>一段JavaScript脚本程序，负责关闭窗口，如果网页不是通过脚本程序打开的（window.open()），调用window.close()脚本关闭窗口前，必须先将window.opener对象置为null，否则浏览器（IE7、IE8）会弹出一个确定关闭的对话框。

```html

<html>
<head>
<script type="text/javascript">
function closeWindow() 
{
 　window.opener = null;
 　window.open(' ', '_self', ' '); 
 　window.close();
}
</script>
</head>
<body>
<input type='button' value='关闭窗口' onClick="closeWindow()">
</body>
</html>

```

对于关闭框架窗口

```js

<script language="javaScript">
function closeWindow() 
{  
    window.opener = null;  
    window.open('', '_top', '');  
    window.parent.close();  
}  
</script>


```