功能仅在其中有警报时才能正确执行

时间:2011-02-02 03:14:33

标签: javascript javascript-events onbeforeunload onunload

我有一个在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;

执行正常。

我遇到的问题是,现在“再见”功能只有在函数中有警报时才能正确执行。你可以在第二行代码中看到alert()。是否有一个函数woujld只能正确执行alert()?

在onbeforeunlaod成功执行之前onunload函数是否正在执行?

0 个答案:

没有答案