I watched a few threads here,mostly used this: window.onbeforeunload = function (e) { var e = e || window.event;

我在这里看了几个线程,主要用于:window.onbeforeunload = function(e){var e = e || window.event;

//IE & Firefox if (e) { e.returnValue = 'Are you sure?'; }

// IE和Firefox if(e){e.returnValue ='你确定吗?'; }

// For Safari return 'Are you sure?'; };

//对于Safari返回'你确定吗?'; };

but seems this will mix the situation of refreshing page and close page, is there any possibility to distinguish these two situations?

但似乎这会混合刷新页面和关闭页面的情况,有没有可能区分这两种情况?

2 个解决方案

#1


function OnUnLoad()
{
    if (window.event.clientY < 0 && window.event.clientX < 0)
    {
        //cleanup code goes here...
    }       
}

This seems to work for me on all browsers. But closing tabs seems to cause issues. Actually, there is not "documented" way of doing it.

这似乎适用于所有浏览器。但是关闭标签似乎会导致问题。实际上,没有“记录”的方式。

更多相关文章

  1. JS在页面加载时候onload与匿名自调用函数的区别
  2. HTML CSS Javascript中 id重复时会发生的 情况
  3. 如何在HTML页面中维护SWF文件的大小?
  4. 鼠标按下时是否可以防止鼠标光标离开页面
  5. 【JavaScript】案例一:使用JS完成注册页面表单校验
  6. electron 将pc端(vue)页面打包为桌面端应用
  7. 从打印页面中删除网址并打印文本
  8. 如何在我的页面上以漂亮的格式显示JSON对象?(复制)
  9. 在不知道序列长度的情况下,在Python中展开多个赋值

随机推荐

  1. linux设置时间和把时间从UTC转成本地时间
  2. mysqk 5.7官方安装指导,比一般有效
  3. Linux&C网络编程————“聊天室”
  4. Linux内核构建系统之一
  5. Linux 下部署Django项目
  6. 如何使用ffmpeg将m4v和wmv视频转换为mp4
  7. Userspace RCU 安装过程记录
  8. linux c 网络编程, 常用网络函数,范例
  9. Linux 多线程 ”一写多读” 模式下的无锁
  10. Linux命令-权限管理命令:chmod