private void WebBrowser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
 {
     if (e.IsLoading == false)
     {
         WebBrowser.EvaluateScriptAsync(AssetResources.SimplifyOnlineMatch);
     }
 }
Example #2
0
 /// <summary>
 /// 调用页面js方法
 /// </summary>
 /// <param name="funcName">函数名</param>
 /// <param name="obj">参数列表</param>
 /// <returns>返回值</returns>
 public string InvokeScript(string funcName, object[] obj)
 {
     try
     {
         string      func = JointMethodStr(funcName, obj);
         ThreadQueue tq   = new ThreadQueue(
             new Task <Task <JavascriptResponse> >(funcEval => {
             return(WebBrowser.EvaluateScriptAsync(funcEval.ToString()));
         }, func), this);
         tq.Start();
         tq.Wait();
         if (null != tq.Result)
         {
             if (null != tq.Result.Result)
             {
                 if (null != tq.Result.Result.Result)
                 {
                     return(tq.Result.Result.Result.ToString());
                 }
             }
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #3
0
        private async void EvaluateJavaScript(string s)
        {
            try
            {
                var response = await WebBrowser.EvaluateScriptAsync(s);

                if (response.Success && response.Result is IJavascriptCallback)
                {
                    response = await((IJavascriptCallback)response.Result).ExecuteAsync("This is a callback from EvaluateJavaScript");
                }

                EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error while evaluating Javascript: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }