在我的聊天应用程序中,当我的应用程序关闭时,我需要得到用户的确认.
So I used the window.onbeforeunload
for confirmation alert and window.onunload
for
logout()
.
-
但这两种功能都在IE和Chrome中发挥作用.(应用程序运行良好)
-
window.onbeforeunload
在Opera中不工作,我的消息将不会在Firefox中显示 -
window.onunload
不在Safari、Opera和Firefox中工作
My JavaScript code will be:
// Used for confirmation, to closing the window
window.onbeforeunload = function () {
return "Are you sure want to LOGOUT the session ?";
};
// Used to logout the session, when browser window was closed
window.onunload = function () {
if((sessionId != null)&&(sessionId!="null")&& (sessionId != ""))
logout();
};
我还用JQuerytry 了同样的功能,
<script type="text/javascript">
$(window).on('beforeunload', function() {
return 'Are you sure want to LOGOUT the session ?';
});
$(window).unload(function() {
if ((sessionId != null) && (sessionId != "null") && (sessionId != "")) {
logout();
}
});
</script>