我究竟做错了什么?
我使用 w3schools.com 进行测试。
webView.Navigate(new Uri("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_alert"));
Package.appxmanifest 文件
导航完成
private async void webView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
string result = await sender.InvokeScriptAsync("eval", new string[] { "window.alert = function (AlertMessage) {window.external.notify(AlertMessage)}" });
}
脚本通知
private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
{
MessageDialog dialog = new MessageDialog(e.Value);
await dialog.ShowAsync();
}