Can't run javascript alerts in universal app's webview at payment gateway

别说谁变了你拦得住时间么 提交于 2019-12-02 03:05:55

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}" });
            }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!