validar validacion vacios formularios formulario enviar ejemplos con codigo carga campos asincrona antes javascript c# webview windows-phone-8.1 payment-gateway

validacion - validar formulario javascript antes de enviar



No se pueden ejecutar las alertas de JavaScript en la vista web de la aplicaciĆ³n universal en la puerta de enlace de pago (1)

Después de golpear mi cabeza por una semana o dos, finalmente encontré la solución, a continuación están los manejadores de eventos necesarios:

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}" }); } }

Estoy integrando la puerta de enlace de pago en mi aplicación universal de Windows donde abro la URL en una vista web. Sin embargo, la vista web no puede mostrar mensajes de alerta de JavaScript o ventanas emergentes. Leí en línea que necesito agregar direcciones URL del sitio web en el manifiesto del paquete para permitir que se ejecute el evento Scriptnotify, pero dado que es una pasarela de pago, no es factible agregar URL para todos los sitios web bancarios. ¿Hay alguna manera de manejar esto?

También estoy manejando el evento ScriptNotify como esto, pero esto parece ser parcialmente correcto.

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)}" }); }