0

実行時にwindow.onbeforeunload実行される関数があります

function goodbye(e) {
//    alert("isSortingOrChangingStatus="+isSortingOrChangingStatus+", hasShadowUserCopy="+hasShadowUserCopy);
    if(!isSortingOrChangingStatus)
    {
        if(playlistModified=="true")//||playlistModified=="True")
        {
            if (!e) e = window.event;
            //e.cancelBubble is supported by IE - this will kill the bubbling process.
            e.cancelBubble = true;
            if(hasShadowUserCopy=="true"||hasShadowUserCopy=="True")
            {
                e.returnValue = 'If you have unsaved playlist changes, you will lose your changes if you press OK now.';
                e.returnValue += '\n\nChanges to Dayparts, Messages or Groups will not be submitted to your devices but will be saved and visible the next time that you log in if you press OK now.';
            }
            else
            {
                e.returnValue = 'You have unsaved playlist changes and will lose your changes if you press OK now.'; //This is displayed on the dialog
            }
            //e.stopPropagation works in Firefox.
            if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
        }
        else
        {
            if(hasShadowUserCopy=="true"||hasShadowUserCopy=="True")
            {
                if (!e) e = window.event;
                //e.cancelBubble is supported by IE - this will kill the bubbling process.
                e.cancelBubble = true;
                e.returnValue = 'If you have unsaved playlist changes, you will lose your changes if you press OK now.';
                e.returnValue += '\n\nChanges to Dayparts, Messages or Groups will not be submitted to your devices but will be saved and visible the next time that you log in if you press OK now.';
                //e.stopPropagation works in Firefox.
                if (e.stopPropagation) 
                {
                    e.stopPropagation();
                    e.preventDefault();
                }
            }
            else{
                return;
            }
        }        
    }
    else
    {
        if(isChangingStatus==true)
        {
            $("#ctl00_cphBody_hfIsChangingStatus").val("true");
        }
    }    
}
window.onbeforeunload = goodbye;

この関数は以前は完全に実行されていました。ライブサイトでテストして、動作することを確認することもできます. この機能にまったく関係のないコードをページにいくつか変更しました。私も追加しました

function resetFrames(){
    parent.document.getElementById("Edit").rows="0%,0%,100%";
}
window.onunload=resetFrames;

これは正常に実行されます。

私が遭遇している問題は、goodbye関数にアラートがある場合にのみ関数が正しく実行されるようになったことです。コードの 2 行目に表示alert()されます。関数が でのみ正しく実行される理由はありalert()ますか?

が正常に実行さonunloadれる前に関数が実行されていonbeforeunloadますか?

4

0 に答える 0