当前位置: 首页>>代码示例>>C#>>正文


C# WebView.InvokeScriptAsync方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Controls.WebView.InvokeScriptAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WebView.InvokeScriptAsync方法的具体用法?C# WebView.InvokeScriptAsync怎么用?C# WebView.InvokeScriptAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Controls.WebView的用法示例。


在下文中一共展示了WebView.InvokeScriptAsync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WebView_DOMContentLoaded

 private async void WebView_DOMContentLoaded(WebView sender)
 {
     if (!Settings.HaveHardwareButtons)
     {
         await sender.InvokeScriptAsync("eval", new[] {HtmlHelper.MarginScript});
     }
     await sender.InvokeScriptAsync("eval", new[] {HtmlHelper.FontColorScript});
 }
开发者ID:Anarh2404,项目名称:TechNews,代码行数:8,代码来源:SwipeableDetailView.xaml.cs

示例2: MainPage

        /// <summary>
        /// Entry point into the page
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();
            SetupTitleBar();
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            LoadingSplash.Visibility = Visibility.Visible;

            var specuri = localSettings.Values["SPEC"];
            if(specuri != null)
            {

                FileWebView = new WebView(WebViewExecutionMode.SeparateThread);
                FileWebView.Name = "FileWebView";
                FileWebView.Source = new Uri(specuri as string);
                FileWebView.ScriptNotify += FileWebView_ScriptNotify;
                FileWebView.LoadCompleted += async (object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e) =>
                {
                    //Inject the scripts into the page
                    string scriptstring = await FileIO.ReadTextAsync(await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Graffiti.js"));
                    FileWebView.InvokeScriptAsync("eval", new List<string> { scriptstring });

                    //Call the loop that marks text and reports what the user has selected
                    FileWebView.InvokeScriptAsync("GetSelectedText", new List<string> { });

                    //Load the annotations from the database
                    await LoadAnnotations(GetSpecID(specuri as string));
                    await AnnotateSpec();

                    //try to load tests, and if they're loaded display them
                    if (await AttemptLoadCachedTests(GetSpecID(specuri as string)))
                    {
                        TestsList.ItemsSource = nonrecursivetestlist.Tests;
                    }

                    //set up UI
                    UpdateStats();

                    //try to log in with cached credentials
                    var loginresult = await github.UseCachedLogin();
                    if (loginresult == "pass")
                    {
                        FinishGitHubLogin();
                    }

                    //get rid of the splash screen
                    HideLoadingSplash.Begin();
                };

                FileWebViewParent.Children.Add(FileWebView);
            }
            else
            {
                HideLoadingSplash.Begin();
            }
        }
开发者ID:DHBrett,项目名称:Graffiti,代码行数:59,代码来源:MainPage.xaml.cs

示例3: InitAsync

 public static async Task InitAsync()
 {
     if (DesignMode.DesignModeEnabled == false)
     {
         WebView webView = new WebView(WebViewExecutionMode.SeparateThread);
         int width = int.Parse(await webView.InvokeScriptAsync("eval", new string[] { "window.screen.width.toString()" }));
         int height = int.Parse(await webView.InvokeScriptAsync("eval", new string[] { "window.screen.height.toString()" }));
         double scale = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
         _width = (int)Math.Ceiling(width * scale);
         _height = (int)Math.Ceiling(height * scale);
     }
     _hadInit = true;
 }
开发者ID:higankanshi,项目名称:MSDevUnion.BingWallpaper,代码行数:13,代码来源:SuitableWallpaperSize.cs

示例4: TaobaoLogin_DOMContentLoaded

 private async void TaobaoLogin_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
 {
     System.Diagnostics.Debug.WriteLine("DOM加载完成");
     var inject = @"window.addEventListener('message',function(args){
         window.external.notify(args.data);
         });";
     await sender.InvokeScriptAsync("eval", new string[] { inject });
 }
开发者ID:cmpute,项目名称:XiamiTing,代码行数:8,代码来源:LoginDialog.xaml.cs

示例5: GetHtmlPage

 private async Task<string> GetHtmlPage(string mangaImageUrl)
 {
     wv  = new WebView();
     //wv.NavigationCompleted += Wv_NavigationCompleted;
     wv.Navigate(new Uri(mangaImageUrl));
     var ss = await WaitForMessageSent();
     if (ss.IsSuccess)
     {
         _content = await wv.InvokeScriptAsync("eval",
             new string[] { "document.documentElement.outerHTML;" });
     }
     return _content;
 }
开发者ID:Chilos,项目名称:ReadManga,代码行数:13,代码来源:MangachanPageParser.cs

示例6: CheckingLoginByManualSuccess

        public async void CheckingLoginByManualSuccess(WebView webView, bool isLoaded)
        {
            if (CheckInternetConnection() || isUserCancel)
                return;

            if (!isLoaded)
            {
                string[] reauthEmail = new string[] { @"document.getElementById('reauthEmail').innerHTML;" };
                string[] emailDisplay = new string[] { @"document.getElementById('email-display').innerHTML;" };
                var accountName = string.Empty;

                try
                {
                    accountName = await webView.InvokeScriptAsync("eval", reauthEmail);
                    
                }
                catch { }

                try
                {
                    accountName = await webView.InvokeScriptAsync("eval", emailDisplay);
                }
                catch { }

                if (accountName != string.Empty)
                    account.UserName = accountName;
            }
            else
            {
                NotifyDownloadStatus(DownloadStatus.LOADING, "...");
                bool success = await IsPageSuccess(webView);

                if (success)
                {
                    NotifyCloseWebViewForm();
                    browser.Navigate(new Uri(GOOGLE_OAUTH2_URL));
                    currentStep = STEP_ACCEPT;
                    return;
                }
                else
                {
                    NotifyDownloadStatus(DownloadStatus.CONTINUE_LOGIN, "");
                    NotifyOpenWebViewForm();
                    System.Diagnostics.Debug.WriteLine("open form");
                    return;
                }
            }
        }
开发者ID:thongvo,项目名称:myfiles,代码行数:48,代码来源:GoogleDownloadController.cs

示例7: GetUserAgent

        /// <summary>
        /// Uses WebView control to get the user agent string
        /// </summary>
        /// <returns></returns>
        private static Task<string> GetUserAgent()
        {
            var tcs = new TaskCompletionSource<string>();

            WebView webView = new WebView();

            string htmlFragment =
              @"<html>
                    <head>
                        <script type='text/javascript'>
                            function GetUserAgent() 
                            {
                                return navigator.userAgent;
                            }
                        </script>
                    </head>
                </html>";

            webView.NavigationCompleted += async (sender, e) =>
            {
                try
                {
                    //Invoke the javascript when the html load is complete
                    string result = await webView.InvokeScriptAsync("GetUserAgent", null);

                    //Set the task result
                    tcs.TrySetResult(result);
                }
                catch(Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            };

            //Load Html
            webView.NavigateToString(htmlFragment);
          
            return tcs.Task;
        }
开发者ID:sanjayasl,项目名称:Q42.WinRT,代码行数:43,代码来源:Util.cs

示例8: Webview_NavigationCompleted

 private async void Webview_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
 {
     string js = "document.getElementsByClassName('header')[0].style.display='none';";
     if (args.Uri.ToString() == "http://m.kugou.com/loginReg.php?act=login&url=http://m.kugou.com")
     {
         title.Text = "登录";
     }
     if (args.Uri.ToString() == "http://m.kugou.com/loginReg.php?act=reg&url=http://m.kugou.com")
     {
         title.Text = "注册";
     }
     if (args.Uri.ToString()== "http://m.kugou.com/")
     {
         js = "window.external.notify(document.cookie)";
     }
     try
     {
         await sender.InvokeScriptAsync("eval", new string[] { js });
     }
     catch (Exception)
     {
         
     }
 }
开发者ID:yszhangyh,项目名称:KuGouMusic-UWP,代码行数:24,代码来源:LoginPage.xaml.cs

示例9: SetDefaultBrowserAgent

        /// <summary>
        /// Установить агент.
        /// </summary>
        /// <returns>Агент.</returns>
        public async Task SetDefaultBrowserAgent()
        {
            var tcs = new TaskCompletionSource<string>(TaskCreationOptions.None);
            var ww = new WebView();
            ww.NavigateToString(@"<html>
    <head>
        <script type='text/javascript'>
            function getUserAgent() 
            { 
                return navigator.userAgent; 
            }
        </script>
    </head>
    <body>
    </body>
</html>");
            ww.NavigationCompleted += async (sender1, e1) =>
            {
                try
                {
                    var ua = await ww.InvokeScriptAsync("getUserAgent", new string[0]);
                    tcs.TrySetResult(ua);
                }
                catch (Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            };
            var task = tcs.Task;
            var tua = await task;
            BrowserUserAgent = tua;
        }
开发者ID:Opiumtm,项目名称:DvachBrowser3,代码行数:36,代码来源:MakabaEngineConfig.cs

示例10: GetHtml

 public static string GetHtml(WebView webView)
 {
     return webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }).GetResults();
 }
开发者ID:CuiXiaoDao,项目名称:MyGit,代码行数:4,代码来源:WebViewBehaviour.cs

示例11: CheckingLoginByManualSuccess

        public async void CheckingLoginByManualSuccess(WebView webView, bool isLoaded)
        {
            if (CheckInternetConnection() || isUserCancel)
                return;

            if (isLoaded)
            {
                NotifyDownloadStatus(DownloadStatus.LOADING, "...");
                bool success = await IsPageSuccessWhenImportingtByManual(webView);

                if (success)
                {
                    NotifyDownloadStatus(DownloadStatus.PROCESSING, "30%");
                    await Task.Delay(4000);
                    var accountName = string.Empty;
                    string[] reauthEmail = new string[] { @"document.getElementsByClassName('msame_Drop_active_email')[0].innerText;" };

                    try
                    {
                        accountName = await webView.InvokeScriptAsync("eval", reauthEmail);
                    }
                    catch { }

                    if (accountName != string.Empty)
                        account.UserName = accountName;

                    System.Diagnostics.Debug.WriteLine("cap nhat username: " + accountName);

                    NotifyCloseWebViewForm();
                    browser.NavigationCompleted += webview_NavigationCompleted;
                    NotifyDownloadStatus(DownloadStatus.PROCESSING, "40%");
                    currentStep = STEP_ACCEPT;
                    browser.Navigate(new Uri(LIVE_OAUTH2_URL));
                }
                else
                {
                    NotifyDownloadStatus(DownloadStatus.CONTINUE_LOGIN, "");
                    NotifyOpenWebViewForm();
                    System.Diagnostics.Debug.WriteLine("open form");
                    return;
                }
            }
        }
开发者ID:thongvo,项目名称:myfiles,代码行数:43,代码来源:LiveHotmailDownloadController.cs

示例12: IsPageSuccess

        private async Task<bool> IsPageSuccess(WebView webView)
        {
            bool hasAccount = false; 
            //var checkArgs = new string[] { @"document.getElementById('shell-header-shopping-cart').offsetLeft < 0 ? '0':'1';" };
            var checkArgs = new string[] { @"document.getElementById('idBtn_Accept').offsetLeft < 0 ? '0':'1';" };

            try
            {
                string val = await webView.InvokeScriptAsync("eval", checkArgs);
                hasAccount = val == "1";
            }
            catch { }

            return hasAccount;
        }
开发者ID:thongvo,项目名称:myfiles,代码行数:15,代码来源:LiveHotmailDownloadController.cs

示例13: IsPageSuccess

        private async Task<bool> IsPageSuccess(WebView webView)
        {
            bool success = false;
            string[] userArgs = new string[] { @"document.getElementById('yucs-signout').offsetLeft < 0 ? '0':'1';" };

            try
            {
                var val = await webView.InvokeScriptAsync("eval", userArgs);
                success = val == "1";
            }
            catch { }

            return success;
        }
开发者ID:thongvo,项目名称:myfiles,代码行数:14,代码来源:YahooDownloadController.cs

示例14: ViewLoaded

        private async void ViewLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
        {
            //if (!this.IsImageUrl(this.viewModel.SelectedItem.Url))
            //{
            //    return;
            //}

            await sender.InvokeScriptAsync("eval", new[] { CssStyle });
        }
开发者ID:jlkalberer,项目名称:Linkslap.WP,代码行数:9,代码来源:View.xaml.cs


注:本文中的Windows.UI.Xaml.Controls.WebView.InvokeScriptAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。