<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>判断用户关闭页面或浏览器</title>
</head>
<body>
<script type="text/javascript">
// 在离开之前写入代码
window.onbeforeunload = function() {return '您确定要离开吗?';};
</script>
</body>
</html>