我有一个在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
函数只有在函数中有警报时才能正确执行。您可以alert()
在第二行代码中看到 。是否有理由仅使用 函数才能正确执行alert()
?
函数是否在成功onunload
执行之前onbeforeunload
执行?