第一个问题:(以下说明只针对IE) 如果当前IE窗口是通过编程方式打开的且不是最后一个IE窗口实例,使用window.close()关闭窗口就不会有提示。也就是说,如果你要关闭的窗口是用window.open()打开的,用window.close()关闭一般就不会有提示MSDN的英文说明如下: How a window is closed programmatically determines whether the user will be prompted with a confirmation dialog box. Invoking the window.close method on a window not opened with script will display a confirmation dialog box. Using script to close the last running instance of Microsoft® Internet Explorer also opens the confirmation dialog box. 第二个问题:例子如下 <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script language="JavaScript"> <!-- function closeWindow() { //在这里放置数据存储处理语句 //如提交一个(隐含)表单到一个隐含帧 //处理语句.... //开始关闭窗口 alert("处理完毕,开始关闭窗口"); window.close(); } //--> </script> </head><body> <input type="button" onClick="javaScript: closeWindow();" value="关闭窗口"> </body> </html>
这种不提示需要IE5.5+以上才不会提示onbeforeunload不是关闭时触发,刷新,转向都会触发
如果当前IE窗口是通过编程方式打开的且不是最后一个IE窗口实例,使用window.close()关闭窗口就不会有提示。也就是说,如果你要关闭的窗口是用window.open()打开的,用window.close()关闭一般就不会有提示MSDN的英文说明如下:
How a window is closed programmatically determines whether the user will be prompted with a confirmation dialog box. Invoking the window.close method on a window not opened with script will display a confirmation dialog box. Using script to close the last running instance of Microsoft® Internet Explorer also opens the confirmation dialog box. 第二个问题:例子如下
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script language="JavaScript">
<!--
function closeWindow()
{
//在这里放置数据存储处理语句
//如提交一个(隐含)表单到一个隐含帧
//处理语句.... //开始关闭窗口
alert("处理完毕,开始关闭窗口");
window.close();
}
//-->
</script>
</head><body>
<input type="button" onClick="javaScript: closeWindow();" value="关闭窗口">
</body>
</html>
http://www.csdn.net/develop/Read_Article.asp?Id=19170严格来说是没有关闭时触发的,这里是指"严格"