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

标签 javascript c# webview windows-phone-8.1 payment-gateway

我正在将支付网关集成到我的通用 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/

相关文章:

javascript - Enter 按键的行为类似于 Javascript 中的 Tab

c# - DynamoDBContext 线程安全吗?

android - android web View 中的 baseUrl 是什么?

android - android 4 (ICS) WebView 中表单元素的焦点区域错误

android 在对话框中加载 webview

javascript - Next-Pwa 无法在 Nginx 等生产服务器上运行

javascript - PHP 将 Canvas 保存为图像时出现 500 Internal Server Error

c# - 要再次显示网页,浏览器需要重新发送信息

c# - 使用.net框架和azure创建实时Web应用程序 - 非常困惑

javascript - 可点击列表元素上的按钮