在浏览器关闭之前关闭 - 如何查找用户是否选择“保持”或“离开” [英] On browser close beforeunload - how to find if user selected "Stay" or "Leave"

查看:122
本文介绍了在浏览器关闭之前关闭 - 如何查找用户是否选择“保持”或“离开”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了让事情变得非常简单 - 我有以下代码:

 
$(window).bind(beforeunload,function(event ){b $ b return'';
})

至少在Chrome,FireFox和IE9上 - 当用户关闭时浏览器 - 他有两个选择 - 留在页面上或离开此页面(该消息因浏览器而异)



现在我怎么找到用户选择什么选项
为简单起见 - 可以说 - 我想根据用户选择的选项显示额外的消息。


类似于 - 只是为了给出一个想法

 
if(option ==Stay on Page)
alert(谢谢你继续留下);
if(选项==离开此页面)
alert(对不起,你决定出发 - 请马上回来);

我如何捕捉 - 用户选择了什么。
非常感谢

解决方案

据我所知,出于安全原因,您不允许这样做。您可以做的唯一事情是:

  window.onbeforeunload = function(){
return'您的确认信息';
}


To keep things very simple - I have the following code

$(window).bind("beforeunload",function(event) {
    return '';
})

Atleast on Chrome,FireFox and IE9 - when a user closes the browser - he is presented with two options - "Stay on Page" or "Leave this Page" (The message varies from browser to browser)

Now how can I find out what option the user selected For sake of simplicity - lets say - I want to show an extra message based on which option the user selected

Something like - just to give an idea

if(option=="Stay on Page")
   alert("Thanks for continuing to stay");
if(option=="Leave this page")
   alert("Sorry you decided to go - please come back soon");

How do I capture - what the user selected. Thanks much

解决方案

As far as I know, you are not allowed to do that, for security reasons. The only thing you can do is the below:

window.onbeforeunload = function(){
    return 'Your confirmation message';
}

这篇关于在浏览器关闭之前关闭 - 如何查找用户是否选择“保持”或“离开”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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