How to change web page background and foreground color in web browser element?

In my application, I put some HTML pages in an element WebBrowser. In some articles, I found that the background of the WebBrowser, as well as the foreground colors, depend on the properties of the HTML page.

How do I change this HTML background and foreground color in my program to view a custom color?

+4
source share
1 answer

You must use the InvokeScriptcontrol's method WebBrowserto introduce some Javascript code, which in turn will change the properties of the element, such as background and foreground colors.

:

public MainPage()
{
    InitializeComponent();

    this.webBrowser1.IsScriptEnabled = true;
    this.webBrowser1.Navigate(new Uri("http://yourpage.com/"));
    this.webBrowser1.LoadCompleted += webBrowser1_LoadCompleted;
}

void webBrowser1_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    this.webBrowser1.InvokeScript("eval", new[] { "document.body.style.background = 'black';" });
}
0

Source: https://habr.com/ru/post/1526293/


All Articles