为什么80%的码农都做不了架构师?>>>   

http://blog.163.com/lgh_2002/blog/static/44017526201061334953256/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>教师直通车网</title>
    <script type="text/javascript">
    window.onbeforeunload = function()
    {
       return ('您确定要离开此页面吗?');
    }
    </script>
</head>
<body>
<a href="http://www.jiaoshiok.com">教师直通车网</a>
</body>
</html>

=======================================================================================

Once in a while people ask me how to catch the IE window’s close event. One thing to use is onbeforeunload event of the window. But the problem in using this event is, you never know when this onbeforeunload event is called. This event could be called for numerous reason like navigation to another page with in the application. So you cannot exactly catch the browser close event using onbeforeunload.

The mouse pointer position comes in handy in this cases. We can effectively harness the power of both onbeforeunloadand clientY position to exactly catch the browser close event.

Code:

window.onbeforeunload = onunload; 
function onunload() 

var closeEvent=false; 
if (event.clientY < 0) 
closeEvent = true;

if ((closeEvent)) 

//Write your code here for close event. 

}

Is there any other efficient way to do this?

Update:

Anonymous: This so very well works with internet explorer 8; i have also tested the tabs it works well. I have given the full code here. However, obviously, there is a requirement: You must allow the execution of javascript.

<HTML> 
<head> 
<script>

window.onbeforeunload = closeit;

function closeit() { 
        var closeEvent = false; 
        alert(event.clientY); 
        if (event.clientY < 0) 
            closeEvent = true;

if ((closeEvent)) { 
            alert("do you want to close the window"); 
            //your actions during closing comes here 
        } 
    }

</script> 
</head> 
<body> 
  <a href="http://blog.163.com/lgh_2002/blog/http://chillicode.wordpress.com">Click here to navigate to 
      Chillicode</a> 
</body> 
</html>

The above code helps us to catch the window close event and there by we can do what ever we wish to do.

In some cases it is enough to just alert the user that he is trying to close the window; how to achieve it? That is even more simple; just return a string value in the closeit function

function closeit()
{return "Any string value here forces a dialog box to \n" +"appear before closing the window.";
}

转载于:https://my.oschina.net/sunyh/blog/110555

离开页面前显示确认提示对话框(兼容IE,firefox) = how to Catch Win...相关推荐

  1. html离开页面时,js实现用户离开页面前提示是否离开此页面的方法(包括浏

    本文实例讲述了js实现用户离开页面前提示是否离开此页面的方法(包括浏览器按钮事件).分享给大家供大家参考.具体如下: 用户离开页面前,提示是否离开此页面(包括浏览器按钮事件) 如果在退出页面时需要弹出 ...

  2. php离开界面监听,js实现用户离开页面前提示是否离开此页面的方法(包括浏览器按钮事件)...

    本文实例讲述了js实现用户离开页面前提示是否离开此页面的方法(包括浏览器按钮事件).分享给大家供大家参考.具体如下: 用户离开页面前,提示是否离开此页面(包括浏览器按钮事件) window.onbef ...

  3. 【JavaScript】离开页面前提示

    离开页面前的提示不能够用onunload去做,由于它仅仅是兼容IE,你要兼容Google与FireFox就蛋疼了. 并且这个事件还是关闭之后才会触发的. 取而代之能够用onbeforeunload去实 ...

  4. 显示消息提示对话框(WebForm)

    1: /// <summary> 2: /// 显示消息提示对话框. 3: /// Copyright (C) Maticsoft 4: /// </summary> 5: p ...

  5. js实现表单form提交前进行确认提示

    在jquery中,可以使用confirm来弹出提示框,实现确认提交.下面小编举例讲解js实现表单form提交前进行确认提示. 工具/原料 js+html 代码编辑器:zend studio 10.0 ...

  6. 实现表单form提交前进行确认提示 表单提交 确认对话框

    没想到有这么多人浏览这个文章,看来网络的文章害人不浅啊,我重新把代码格式化了,大家好好看吧. 感谢网友提醒,把οnsubmit="return sumbit_sure()" 改过来 ...

  7. form提交前进行确认提示

    οnsubmit="return confirm('确定提交吗?')" <form action="xxx" onsubmit="return ...

  8. chrome 不记录填写值,Chrome 中使用 onbeforeunload 来提示离开页面时数据是否已保存...

    最简单的写法如下,效果是只要用户在当前页面有任何动作,在页面离开时都会显示确认框. 注意:这里返回的字符串原本是自定义的确认框消息,但现在已经不再支持了,仅显示浏览器默认的提示信息. ```javas ...

  9. 谷粒学苑 —— 8、课程管理:课程发布页面3 —— 信息确认及发布

    目录 1.确认信息的显示 1.1.后端 1.1.1.定义确认信息 VO 1.1.2.根据课程 ID 获取确认信息 1.1.3.测试异常:Invalid bound statement (not fou ...

最新文章

  1. 【转】DHCP工作过程详解
  2. 我的Android进阶之旅------gt;Java全角半角的转换方法
  3. scrapyd部署爬虫项目到LINUX服务器
  4. 梯度下降法进行线性回归---------二维及多维
  5. 互联网公司忽悠员工的黑话
  6. concurrent: Callable用法
  7. VMware Workstation Pro 16 安装教程
  8. P3808,P3796-[模板]AC自动机(简单版/加强版)
  9. WordPress模板-ripro主题系列对接易支付通用模块插件
  10. html表格制作应该注意什么软件,html表格制作
  11. 计算机数字雨代码,cmd命令数字雨教程
  12. java中undefined如何解决_js对undefined的处理
  13. (附源码)计算机毕业设计ssm高校第二课堂管理系统
  14. linux查看文件打开限制,Linux最大文件打开数使用经验详解
  15. 腾讯的wifi硬件“全民wifi”正是亮相,有何值得期待
  16. JAVA定义一个树形的结构_Java自定义树形结构
  17. 看完一本青春小说后的感悟。
  18. 多道批处理操作系统和分时操作系统的概念
  19. vrchat模型保存_轻松简单自己上传VRChat的Avatar
  20. 互动应用开发p5.js——音视频交互

热门文章

  1. “脑补”的科学依据:眼前的黑不是黑,靠得是你的大脑
  2. “领导跳槽想带我走,我要不要跟?”
  3. 连自己都不放过?六成应用开发不需要程序员!
  4. 服!AI 让兵马俑“活”起来,颜值惊艳!
  5. 程序员的求生欲有所强?用 Python 花式哄女友
  6. Jenkins进阶系列之——01使用email-ext替换Jenkins的默认邮件通知
  7. Coding and Paper Letter(二十)
  8. 一个仿微信朋友圈的图片查看框架 - PhotoViewer
  9. vs2017 编码约定——.editorconfig文件
  10. 例5.12 输入一串字符,字符个数不超过100,且以.结束。 (信息学奥赛一本通)...