开发者

WebBrowser.Document.Body.InnerHtml strange behavior

I'm trying to load page and t开发者_高级运维hen 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;
}


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜