$(窗口).unload(函数(){});在Firefox和Opera中没有被解雇?

时间:2013-04-23 09:28:01

标签: javascript firefox opera jquery

我之前的帖子将是window.onbeforeunload and window.onunload is not working in Firefox , Safari , Opera?,并且在这种情况下无效。所以我创建了一个新帖子。

现在,这适用于IEsafarichrome

仅在beforeunloadfirefox中触发的unload事件未被解雇。

两者都不在Opera

我的jquery将是,

$(window).on('beforeunload', function() {
        return 'Are you sure want to LOGOUT the session ?';
});

$(window).unload(function() {
        closeWindow();
});

function closeWindow(){
    alert("fdf");
    $.ajax(
            {
                type: "post",
                url: "Test.jsp",
                async:     false,
                //data : "userId="+encodeURIComponent(userId)+"&secureKey="+encodeURIComponent(secureKey)+"&nickname="+encodeURIComponent(name)+"&sid="+Math.random() ,
                cache:false,
                contentType: "application/x-www-form-urlencoded; charset=utf-8",
                scriptCharset: "utf-8" ,
                dataType: "html",
                //alert(sessionId+" "+userId+ " "+secureKey+" "+message);

                error: function (xhr, ajaxOptions, thrownError) {
                //alert("status :"+xhr.status+"\nthrownError : "+thrownError+"\nresponseText : "+xhr.responseText);
            },

            success: function( responseData , status){
                //alert("LogoutAction Response Data : "+ responseData +"\nStatus : "+status);
                var checkMsg = $.trim(responseData);

                if(checkMsg != "null" && checkMsg.length != 0  && checkMsg != null){

                        alert("Window close : "+checkMsg);

                }
            }
            }                           
    );

}

我的Test.jsp将是,

<%  System.out.println("Window is closed !"); 
out.println("Window is closed !");   %>

1 个答案:

答案 0 :(得分:-1)

您需要从卸载事件回调中返回一些内容 -

$(window).unload(function() {
        closeWindow();
        return "some string";
});