Search code examples
c#xamlwebviewuwpuwp-xaml

How to exit an UWP webview application?


I'm creating an UWP WebView app with the web URI. Currently, I'm trying to implement the exit functionality for the same.

So when I click on exit option I'll be given a popup with "yes" and "cancel" buttons so on click of "yes" I need to exit the app. So I've added the below mentioned code in the click function of my JS file.

window.external.notify("close");

and I'm using the code that I've found one of the stack overflow forums that we can use to add the functionality for the exit app using the script notify part.

as mentioned here https://stackoverflow.com/a/48212615/15189804

But to make this functionality work I need to define the URI in the packagemanifest as mentioned there.

Is there any other way where I can use this method without defining the URI in the packagemanifest?

NOTE: URI that I've been using is 'https'.

Thanks in advance and happy coding.


Solution

  • According to the documentation of WebView.ScriptNotify, you must define the URI in the packagemanifest. AllowedScriptNotifyUris is unavailable for releases beginning with Windows 8.1. Instead, list URIs under ApplicationContentUriRules in the package manifest

    To enable an external web page to fire the ScriptNotify event when calling window.external.notify, you must include the page's URI in the ApplicationContentUriRules section of the app manifest.