本文整理汇总了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});
}
示例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();
}
}
示例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;
}
示例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 });
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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)
{
}
}
示例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;
}
示例10: GetHtml
public static string GetHtml(WebView webView)
{
return webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }).GetResults();
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例14: ViewLoaded
private async void ViewLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
{
//if (!this.IsImageUrl(this.viewModel.SelectedItem.Url))
//{
// return;
//}
await sender.InvokeScriptAsync("eval", new[] { CssStyle });
}