Wednesday, May 11, 2005

EnableLeaveAuthoringWarning - A Closer look

After Mei Ying's post about Getting Rid of the Leave Warning Alert after a Preview and Stefan's comment I thought of checking EnableLeaveAuthoringWarning more deeper. If EnableLeaveAuthoringWarning is set to true, Console generate this script to the page,

var __consoleCachedOriginalPostBack;
if( eval("window.__doPostBack") != null )
{
__consoleCachedOriginalPostBack = __doPostBack;
__doPostBack = __consoleCustomDoPostBack;
} __consoleCachedOriginalOnSubmit = __CMS_PostbackForm.onsubmit; __CMS_PostbackForm.onsubmit = __consoleHandleOnSubmit;
function __consoleCustomDoPostBack( eventTarget, eventArgument )
{
WBC_offWarningBeforeLeave();
__consoleCachedOriginalPostBack( eventTarget, eventArgument );
}
function __consoleHandleOnSubmit()
{
WBC_offWarningBeforeLeave();
if (__consoleCachedOriginalOnSubmit != null)
{
__consoleCachedOriginalOnSubmit();
}
}

where if it is false it generates

WBC_offWarningBeforeLeave();

Both are totally different. As Stefan explained in his post - How to disable the "Leave Authoring" warning for a specific control rather than for the whole template (last update: 08/12/2004),"So the problem is that using href in anchor tags will not allow the client side code to be executed that checks if the current action is actually a postback or if the user really decided to leave the page. If the redirect would have been done using the onclick attribute rather than the href this would not have happened."

It is true for the first instance (where EnableLeaveAuthoringWarning = true). But in the second place, there are no client side script to check this! This is fine until CMS_restoreAfterPreviewPostback() get called. Because upto that point global variable g_bWarnBeforeLeave is set to false. So any call to beforeUnload wont bring the warning because beforeUnload will check whether g_bWarnBeforeLeave is true or not to give the warning. But the function CMS_restoreAfterPreviewPostback() set g_bWarnBeforeLeave to true, so until WBC_offWarningBeforeLeave() get called, it will be true (eg : another postback). Which means after a preview first action will give the warning message even if EnableLeaveAuthoringWarning is set to false, because the preview set g_bWarnBeforeLeave to true.

As a solution it can be resolved by Getting Rid of the Leave Warning Alert after a Preview or by this one.

0 Comments:

Post a Comment

<< Home