tags:

views:

211

answers:

2

I'm trying to load page and then remove some elements in it. While doing that I encountered strange behavior. When I do

webBrowser1.Document.Body.InnerHtml = webBrowser1.Document.Body.InnerHtml;

It turns off some JavaScript code, for example for Google.com it turns off auto completion. Why is that? I suppose it has something to do with JavaScript initialization, if so how can I reinitialize the page?

upd: Just created new project, placed 2 buttons & WebBrowser. Same thing. Here is the code

private void button1_Click(object sender, EventArgs e)
{
    webBrowser1.Navigate("http://google.com");
}

private void button2_Click(object sender, EventArgs e)
{
    webBrowser1.Document.Body.InnerHtml = webBrowser1.Document.Body.InnerHtml;
}
A: 

Im not sure why you have that' webBrowser1' part in those lines of code to start with.

I would assume that most of those auto completes are getting applied once the page has loaded. They presumably monitor the respective elements but are not directly attached to those elements. Thus when you, in effect, reset the Body of the HTMl for the page, the elements that the JS is 2watching are removed, but are never called again. I hear that google do some funny stuff to the JS to make it hard for people to see what it is.

thecoshman
webBrowser1 is a Control of type WebBrowser on my form. Actually I'm working with different website, just took google for an example.
Poma
Bit confused as to why I got down voted there... If webBrowser1 is form element, then it dose not make sense to then try and access its Document.Body.InnerHTML property. I know that google.com was an example, and thus I used your example to explain why I belive such behaviour is happening. But In light of your comment, I would imagine that your code is just confusing the JS engine.What browser are you using? dose it happen the same in other ones?
thecoshman
It's not me :) I can't down vote cause I have reputation less than 100
Poma
As for browser - this is standard control from `System.Windows.Forms` (Framework version 3.5). I think it is using IE engine.
Poma
Not trying to accuse any one. Just would like to know what was 'bad' about my answer, other then the fact I did not give an exact one, but then the question is rather lose any way.
thecoshman
Oh! So your not using a conventional web page with JavaScript. This changes things a bit. Why then, if your making a C# app, have you got JavaScript running as well? Doesn't make sense to me. Admittedly, I'm not much of a C# fan so not too used to it.
thecoshman
A: 

Solved this issue. It turned out that setting InnerHtml property breaks DOM structure. The solution is to use Microsoft.mshtml namespace and methods like appendChild and removeChild.

Poma