Sometimes you need to provide data back to the application from the WebView. A good example of this is when you call a script that needs to send back a return value. To do this, you handle the ScriptNotify event in the app, and then in the script, you use window.external.notify("return value"), where "return value" is the data that you want to pass back.

Scripts loaded into the WebView via the NavigateToString method are allowed to send results back via the ScriptNotify event. Scripts loaded via the Navigate method are only allowed to notify the host if it's an ms-appx-web URL, an ms-local-stream URL, or a URL that's included in the ApplicationContentUris section of the package manifest.

In the output below, the HTML shown on the left side is loaded into a WebView control. When the ScriptNotify event is processed, a message will appear on the right side. Click the "Reload" button to reload the HTML and trigger another ScriptNotify event.