在关闭标签页/浏览器之前进行确认 [英] Confirmation before closing of tab/browser

查看:338
本文介绍了在关闭标签页/浏览器之前进行确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在用户离开页面之前向用户发送确认信息?



我在不同的地方搜索了这个问题,但他们提到的所有内容都是用的javascript window.unload & window.onbeforeunload

在大多数时候,它在铬中不起作用,因为它被阻止。
解决方案

试试这个:

 < script> 
window.onbeforeunload = function(e){
e = e || window.event;

//对于版本4之前的IE和Firefox
if(e){
e.returnValue ='当然?';
}

//对于Safari
返回'是吗?';
};
< / script>

以下是一份工作 jsFiddle


How to ask confirmation from user before he leaves the page as in gmail?

I searched for this question in various places, but all that they mention is the use of javascript window.unload & window.onbeforeunload. Also it doesn't work in chrome most of the times as it gets blocked.

解决方案

Try this:

<script>
window.onbeforeunload = function (e) {
    e = e || window.event;

    // For IE and Firefox prior to version 4
    if (e) {
        e.returnValue = 'Sure?';
    }

    // For Safari
    return 'Sure?';
};
</script>

Here is a working jsFiddle

这篇关于在关闭标签页/浏览器之前进行确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆