예제 #1
0
        private void cefJsDialog_JsDialog(object sender, JsDialogEventArgs e)
        {
            string script = "$(\"#cefMsg\").html(\"" + e.messageText + "\");";

            e.callback.Continue(true, string.Empty);
            e.suppressMessage = false;
            e.result          = true;
            if (e.messageText.Contains("过于频繁"))
            {
                script += "setTimeout(\"bindNext()\", 1500);";
                webBrowser.GetMainFrame().ExecuteJavaScriptAsync(script);
            }
            else if (e.messageText.Contains("验证码错误"))
            {
                script += "codeErrorRetry();";
                webBrowser.GetMainFrame().ExecuteJavaScriptAsync(script);
            }
            //else if (e.messageText.Contains("预约成功"))
            //{
            //    webBrowser.GetMainFrame().ExecuteJavaScriptAsync(script);
            // }
            else if (e.messageText.Contains("已经约满"))
            {
                script += "afternoonNext();";
                webBrowser.GetMainFrame().ExecuteJavaScriptAsync(script);
            }
            else
            {
                webBrowser.GetMainFrame().ExecuteJavaScriptAsync(script);
            }
        }
 void ICefWebBrowserInternal.OnJSDialog(JsDialogEventArgs ea)
 {
     // Raised on UI thread. Invoke is needed if multi-threaded-message-loop is used.
     this.DispatchIfRequired(() =>
     {
         try
         {
             if (JSDialog != null)
             {
                 JSDialog(this, ea);
             }
         }
         catch (Exception ex)
         {
             Logger.Error("Error in OnJSDialog : {0}. Dialog will be suppressed.", ex);
             ea.SuppressMessage = true;
         }
         finally
         {
             // Tell CEF we handled the dialog
             ea.Handled = true;
         }
     });
 }