Fork me on GitHub

确认关闭网页

当用户关闭页面时,弹出对话框,让用户确认是否关闭,选择确定则页面关闭,否则页面不关闭。如下图所示,这个是非常常见。

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>确认关闭网页</title>
</head>

<body  onbeforeunload = "return  '确定关闭网页?';">
    <input type="button"  onclick="javascript:window.opener = null; window.open('','_self'); window.close();" value="关闭网页"/>
</body>
</html>

既然有关闭页面的弹出框,那肯定也有“关闭这个窗口,进入另一个页面”,其实是相同的道理

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>关闭本网页,进入新页面</title>
</head>
<body>
    <input type="button"  onclick="javascript:window.open('淘宝导航菜单.html','','fullscreen=yes,menubar=no,resizable=no');window.opener = null;window.close();"  value="打开新页面"/>
</body>
</html>

 

posted on 2014-03-04 16:09  雨为我停  阅读(518)  评论(0编辑  收藏  举报