【发布时间】:2024-01-08 18:22:01
【问题描述】:
我做错了什么?
我使用 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();
}
【问题讨论】:
-
您预计会发生什么,它正在做什么?
-
我想收到警报消息like this (screenshot)
标签: c# webview uwp webbrowser-control invokescript