[英]Can't run javascript alerts in universal app's webview at payment gateway
I am integrating payment gateway in my universal windows app where I open the URL in a webview. 我正在将付款网关集成到通用Windows应用程序中,在该应用程序中,我可以在Webview中打开URL。 However, webview can't seem to display javascript alert messages or popups.
但是,webview似乎无法显示javascript警报消息或弹出窗口。 I read online that I need to add url's of website in package manifest to enable Scriptnotify event to run but given it's a payment gateway, it's not feasible to add url's for all bank websites.
我在网上阅读到我需要在软件包清单中添加网站的网址以使Scriptnotify事件能够运行,但是鉴于它是一个付款网关,因此不可能为所有银行网站添加网址。 Is there a way to handle this ?
有办法解决吗?
Also I am handling the ScriptNotify event as this, but this seems to be partially correct. 我也这样处理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)}" });
}
After banging my head for a week or two, finally found the solution, following are the necessary event handlers : 经过一两个星期的努力,终于找到了解决方案,以下是必要的事件处理程序:
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}" });
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.