在我的聊天应用程序中,当我的应用程序关闭时,我需要得到用户的确认.
所以我使用了window.onbeforeunload确认警报和window.onunloadlogout().
但这两个功能都在IE和Chrome中运行.(应用程序运行正常)
window.onbeforeunload 没有在Opera工作,我的消息将不会在Firefox中显示.
window.onunload 不适用于Safari,Opera和Firefox.
我的javaScript代码将是,
// 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();
};
Run Code Online (Sandbox Code Playgroud)
我也尝试了与JQuery相同的功能,
<script type="text/javascript">
$(window).on('beforeunload', function() {
return 'Are you sure want to LOGOUT the session ?';
});
$(window).unload(function() …Run Code Online (Sandbox Code Playgroud)