onunload和window.onunload在Firefox、Safari和Opera中不起作用?在我的聊天应用程序中,当我的应用程序关闭时,我需要得到用户的确认。所以我用了window.onbeforeunload确认警报和window.onunload用于注销()。但这两种功能都在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();};我在JQuery中也尝试了相同的函数,<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>
3 回答
三国纷争
TA贡献1804条经验 获得超7个赞
var myEvent = window.attachEvent || window.addEventListener;var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable myEvent(chkevent, function(e) { // For >=IE7, Chrome, Firefox var confirmationMessage = 'Are you sure to leave the page?'; // a space (e || window.event).returnValue = confirmationMessage; return confirmationMessage; });
慕后森
TA贡献1802条经验 获得超5个赞
onunload
xmlhttp.open("POST","LogoutAction",false);
添加回答
举报
0/150
提交
取消