gpt4 book ai didi

javascript - 无法在支付网关的通用应用程序的 Web View 中运行 JavaScript 警报

转载 作者:行者123 更新时间:2023-11-28 00:01:01 25 4
gpt4 key购买 nike

我正在将支付网关集成到我的通用 Windows 应用程序中,我在 Web View 中打开 URL。但是,webview 似乎无法显示 javascript 警报消息或弹出窗口。我在网上读到,我需要在包 list 中添加网站的 url,以使 Scriptnotify 事件能够运行,但考虑到它是支付网关,为所有银行网站添加 url 是不可行的。有办法解决这个问题吗?

我也这样处理 ScriptNotify 事件,但这似乎部分正确。

private async  void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(e.Value);

await dialog.ShowAsync();
}


private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
string result = await this.MyWebView.InvokeScriptAsync("eval", new string[] { "window.alert = function (AlertMessage) {window.external.notify(AlertMessage)}" });

}

最佳答案

经过一两周的苦思冥想,终于找到了解决方案,以下是必要的事件处理程序:

private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
string result = await this.MyWebView.InvokeScriptAsync("eval", new string[] { "window.confirm = function (ConfirmMessage) {window.external.notify(ConfirmMessage)}" });
}


private async void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{

Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(e.Value);
dialog.Commands.Add(new UICommand("Yes"));
dialog.Commands.Add(new UICommand("No"));

// Set the command that will be invoked by default
dialog.DefaultCommandIndex = 0;

// Set the command to be invoked when escape is pressed
dialog.CancelCommandIndex = 1;

var result = await dialog.ShowAsync();

if (result.Label.Equals("Yes"))
{
string res = await MyWebView.InvokeScriptAsync("eval", new string[] { "window.confirm = function (ConfirmMessage) {return true}" });
}
else
{
string res = await MyWebView.InvokeScriptAsync("eval", new string[] { "window.confirm = function (ConfirmMessage) {return false}" });
}
}

关于javascript - 无法在支付网关的通用应用程序的 Web View 中运行 JavaScript 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31804380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com