Dynamically Change Css Styles in C# (Sharp) Without Asp
<p>Hi all hopefully this is a quick one.<br>
I'm working on a c# web browser that, amongst other things, changes css styles of web pages like google and facebook. for example it will make the background on facebook and google red instead of white. i've had success but its not at all consistent and i have no idea why.<br></p>

<pre><code>HtmlDocument doc = Browser1.Document;
HtmlElement textElem = doc.CreateElement("DIV");
textElem.InnerHtml = "&lt;STYLE&gt;body{background-color:red!important}&lt;/STYLE&gt;";
doc.Body.AppendChild(textElem);
</code></pre>

<p>that code works on www.google.com but not www.rationality.tk however..</p>

<pre><code>HtmlElement head = Browser1.Document.GetElementsByTagName("body")[0];
head.SetAttribute("bgcolor", "red");
</code></pre>

<p>That  code works on <a href="http://rationality.tk" rel="nofollow">www.rationality.tk</a> but not <a href="http://google.com" rel="nofollow">www.google.com</a> and both codes do not work on www.facebook.com which i cannot get anything to work on.</p>

<p>I'm probably doing something wrong and I just moved on to c# after giving up on c++ and I have found it a lot easier but still getting the hang of it. thank you in advance.</p>

<p>EDIT: PROBLEM SOLVED <br></p>

<pre>HtmlElement head = Browser1.Document.GetElementsByTagName("body")[0];
head.Style = "background-color:red";</pre>

<p>this works on facebook, google and rationality.tk</p>
