C# WebBrowser control — Get Document Elements After AJAX?

后端 未结 7 794
[愿得一人]
[愿得一人] 2020-11-27 14:01

I\'m writing an application that uses the WebBrowser control to view web content that can change with AJAX that adds new content/elements. I can\'t seem to get at the new el

7条回答
  •  误落风尘
    2020-11-27 14:33

    How about running javascript to caption the element and displaying it in a new window?

    I haven't tested it out but it may work.

    (WebBrowser)w.Navigate("javascript:GetElementById('div').innerHtml;", true);
    

    The true attribute to open the return in a new windows. (Or a frame or maybe you can find a better way)

    To capture the NewWindow event you'll need to reference the SHDocVw.dll which is in your Windows/System32 folder. Then you can cast your WebBrowser Control like this:

    SHDocVw.WebBrowser_V1 browser = (SHDocVw.WebBrowser_V1)(WebBrowser)w.ActiveXInstance;
    

    You can have it close right away after storing the response. Well good luck and let me know how it goes.

提交回复
热议问题