Hi,
Yes, you can prevent the user from accidentally leaving the application by registering the OnBeforeUnloaded event of the JavaScript "window" object. Doing so will cause a confirmation dialog to appear when the user attempts to close the app. The default text of the confirmation dialog is something like "Do you really want to leave?".
Rather than registering this JavaScript event manually by modifying the generated "index.html" file, I suggest that you register this JavaScript event from your C# code using the "Interop.ExecuteJavaScript" method (available in CSHTML5 1.0 beta 7.2 or newer).
For example, just add the following code to the constructor of App.xaml.cs:
Code: Select all
Interop.ExecuteJavaScript(@"
window.onbeforeunload = function (e) {
var e = e || window.event;
// For IE and Firefox
if (e) {
e.returnValue = 'Here you can append text to the default confirmation dialog text.';
}
// For Safari
return 'Here you can append text to the default confirmation dialog text.';
}
");
Regards,
JS-Support