当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在用户离开页面时提示信息

ASP
ASP设计常见问题及解答精要-1
ASP设计常见问题及解答精要-2
ASP设计常见问题及解答精要-3
ASP设计常见问题及解答精要-4
asp学习入门经验谈
如何才能成为一名真正的Web程序员
手把手教你在ASP中使用SQL语句
ASP与数据库应用(给初学者)
亲密接触ASP.Net(1)
亲密接触ASP.Net(2)
亲密接触ASP.Net(3)
亲密接触ASP.Net(4)
亲密接触ASP.Net(5)
.Net边学边讲(一)
.Net边学边讲(二)
.Net边学边讲(三)
NET移植案例学习:建造Web站点(1)
NET移植案例学习:建造Web站点(2)
ASP 3.0高级编程(四十)
深入研究Application和Session对象(1)

ASP 中的 在用户离开页面时提示信息


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 158 ::
收藏到网摘: n/a

    有时候在编辑页面用户做修改后,可能会有刷新、关闭等误操作造成当前页面信息的丢失,
何不先提醒一下用户呢?实例代码如下:

<!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>