无法 运行 javascript 在支付网关的通用应用程序 webview 中提醒
Can't run javascript alerts in universal app's webview at payment gateway
我将支付网关集成到我的通用 windows 应用程序中,我在该应用程序中在网络视图中打开 URL。但是,webview 似乎无法显示 javascript 警报消息或弹出窗口。我在网上看到我需要在包清单中添加 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}" });
}
}
我将支付网关集成到我的通用 windows 应用程序中,我在该应用程序中在网络视图中打开 URL。但是,webview 似乎无法显示 javascript 警报消息或弹出窗口。我在网上看到我需要在包清单中添加 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}" });
}
}