Donato
Donato

Reputation: 13

Is it possible to get html code in WebViewControl in Windows Form Application?

Just like in the WebBrowser controller, the following code can be used to retrieve the html code. I've tried everything but I haven't found anything like that for WebView Controller

webBrowser.DocumentText

Upvotes: 0

Views: 436

Answers (1)

Castorix
Castorix

Reputation: 1555

For example, for a webView1 control in Winforms with the Microsoft.Toolkit.Forms.UI.Controls.WebView package :

webView1.NavigationCompleted += new System.EventHandler<Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlNavigationCompletedEventArgs>(this.webView1_NavigationCompleted);

and :

private async void GetPageHTML()
{
    sHTMLSource = await webView1.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
}

private string sHTMLSource = null;
private void webView1_NavigationCompleted(object sender, Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlNavigationCompletedEventArgs e)
{
    GetPageHTML();
}

Upvotes: 1

Related Questions