4

In my application I am rendering some HTML pages into a WebBrowser element. In some articles I found that the WebBrowser's background as well as foreground colors depend on the HTML page properties.

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

AymenDaoudi
  • 7,811
  • 9
  • 52
  • 84
Pradeep Kesharwani
  • 1,480
  • 1
  • 12
  • 21
  • Inject CSS. See this for further details: http://stackoverflow.com/questions/14113311/inject-serve-custom-css-in-wp8-webbrowser-control – sibbl Feb 11 '14 at 10:18

1 Answers1

0

You should use the InvokeScript method of the WebBrowser control to inject some Javascript code that will in turn change element properties like background and foreground colors.

Sample code:

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';" });
}
Olivier Payen
  • 15,198
  • 7
  • 41
  • 70