有时候在编辑页面用户做修改后,可能会有刷新、关闭等误操作造成当前页面信息的丢失,
何不先提醒一下用户呢?实例代码如下:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>confirm before leave</title>
<script language="javascript" type="text/javascript">
<!--
var pb_strconfirmclosemessage;
var pb_blnclosewindow = false;
pb_strconfirmclosemessage ="您真的要离开本页吗?";
function confirmclose() {
window.event.returnvalue = pb_strconfirmclosemessage;
pb_blnclosewindow = true;
}
function showconfirmclose(blnvalue) {
if(blnvalue) {
document.body.onbeforeunload = confirmclose;
} else {
document.body.onbeforeunload = null;
}
}
//--></script>
</head>
<body onload="showconfirmclose(true);">
<input type=button value="提示" onclick="showconfirmclose(true);">
<input type=button value="不提示" onclick="showconfirmclose(false);">
<input type=button value="测试刷新" onclick="window.location.reload();">
</body>
</html>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器