示例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>
<title>关闭页面提示</title><base target="_blank" />
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body οnbefοreunlοad="return '确定关闭页面吗?';">
<h1>适用单个窗口关闭,如果直接关闭整个浏览器,这个就没作用</h1>
<div><input οnclick="javascript:window.opener=null;window.open('','_self');window.close();" type="button" value="关闭页面"/></div>
</body>
</html>
所以如果关闭浏览器前需要其他操作,如下方法:
window.onbeforeunload = function () { //关闭前会执行,但是必须加return任意字符串
return "确认离开当前页面";};