LINQPad secret - WebView2 and adding HTML items later
I did an example in Windows Forms with the WebView2 control.
I can load HTML text into the WebView2 using a string.
using Microsoft.Web.WebView2.WinForms;
namespace WebView2WinForms;
public partial class Form1 : Form
{
private WebView2? _browser;
public Form1() { InitializeComponent(); InitializeWebView(); } private async void InitializeWebView() { _browser = new WebView2 { Dock = DockStyle.Fill }; Controls.Add(_browser); await _browser.EnsureCoreWebView2Async(); //_browser.Source = new Uri("https://www.google.com"); var html = @"<html> <head> <title>Basic Web Page</title> </head> <body> Hello World! </body> </html>"; _browser.NavigateToString(html); }
}
I'm wondering how LINQPad can add more HTML items - after displaying the first one - without reload/set the whole page.
This is very interesting to know, if it is not a super secret ;-)
async Task Main()
{
TimeZoneInfo.Local.Dump();
await Task.Delay(2000);
TimeZoneInfo.Local.Dump();
await Task.Delay(2000);
TimeZoneInfo.Local.Dump();
}
Comments
https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model
Ok, thank you, now I understand. I leave the above modified example for reference:
using Microsoft.Web.WebView2.WinForms;
namespace WebView2WinForms;
public partial class Form1 : Form
{
private WebView2? _browser;
}
innerHTML
is considered obsolete, there are other ways to do it.