Both Chrome and Firefox have a ‘feature’ which allows a user to ignore future calls to confirm(). Once this has been checked, any subsequent calls to confirm() return false immediately without showing the window.
In XAF, this behaviour prevents the application from working correctly. For instance, it becomes impossible to confirm a deletion.
The following controller provides a work around. It injects some javascript into the page wrapping the call to confirm(). The new code detects when the Prevent this page from creating additional dialogs checkbox has been checked and returns true instead. The confirmation window still does not appear, but the XAF application works as if the user had pressed confirm instead of cancel.
usingDevExpress.ExpressApp;usingDevExpress.ExpressApp.Web;usingDevExpress.Web.Internal;namespaceNetModule.Web.Controllers{publicclassHandleDisabledConfirmationsController:Controller{publicstaticboolIsChrome{get{returnRenderUtils.Browser.IsChrome;}}publicstaticboolIsFirefox{get{returnRenderUtils.Browser.IsFirefox;}}protectedoverridevoidOnFrameAssigned(){base.OnFrameAssigned();if(IsChrome||IsFirefox){WebWindowwindow=FrameasWebWindow;if(window!=null){window.CustomRegisterTemplateDependentScripts+=window_CustomRegisterTemplateDependentScripts;}}}privatevoidwindow_CustomRegisterTemplateDependentScripts(objectsender,CustomRegisterTemplateDependentScriptsEventArgse){// wrapper for 'confirm'WebWindowwindow=(WebWindow)sender;// Detect the user has checked the 'prevent this page from creating additional dialogs'.// In which case assume all confirmations are accepted, rather than the default rejectedvarconfirmWrapper=@"<script>window.nativeConfirm=window.confirm;window.confirm=function(message){vartimeBefore=newDate();varconfirmBool=nativeConfirm(message);vartimeAfter=newDate();if((timeAfter-timeBefore)<350){confirmBool=true;}returnconfirmBool;}</script>";e.Page.ClientScript.RegisterClientScriptBlock(GetType(),"WrapConfirmations",confirmWrapper);}protectedoverridevoidOnDeactivated(){if(IsChrome||IsFirefox){WebWindowwindow=FrameasWebWindow;if(window!=null){window.CustomRegisterTemplateDependentScripts-=window_CustomRegisterTemplateDependentScripts;}base.OnDeactivated();}}}}
The controller works by timing the milliseconds to close the confirmation window. If it is less than 350 milliseconds we can assume the confirmation window never opened owing to the checkbox. In this scenario, it returns true (confirm) rather than false (cancel) in order for XAF to function correctly.