C#WebBrowser控件 - 获取文档元素的AJAX后? [英] C# WebBrowser control -- Get Document Elements After AJAX?
问题描述
我在写一个使用WebBrowser控件来查看网页内容,可以使用AJAX,增加了新的内容/要素变化的应用程序。 我似乎无法得到的新元素什么办法我试过。 BrowserCtl.DocumentText没有了最新的网页,当然这不是查看源文件中无论是。
是否有某种方式使用此控件来得到这个新的数据? :( 请帮忙。谢谢!
IE浏览器:
Browser.Navigate(www.somewebpagewithAJAX.com);
// code表示等待浏览器来完成...
...
// WebBrowser控件加载内容和AJAX加载新的内容
//(可见在运行时的形式),但不能看到他们在Browser.Document.All
//或Browser.DocumentText :(
我解决了这个问题对我来说。
最关键的是,附加处理程序 onPropertyChanged
事件的div元素正在被通过Ajax调用填充。
的HtmlElement目标= webBrowser.Document.GetElementById(div_populated_by_ajax);
如果(目标!= NULL)
{
target.AttachEventHandler(onpropertychange,处理程序);
}
最后,
私人无效处理程序(对象发件人,EventArgs的)
{
HtmlElement元素的div = webBrowser.Document.GetElementById(div_populated_by_ajax);
如果(DIV == NULL)回报;
字符串contentLoaded = div.InnerHtml; //获得通过AJAX加载内容
}
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 elements any way I've tried. BrowserCtl.DocumentText doesn't have the up-to-date page and of course it's not in "view source" either.
Is there some way to get this new data using this control? :( Please help. Thanks!
IE:
Browser.Navigate("www.somewebpagewithAJAX.com");
//Code that waits for browser to finish...
...
//WebBrowser control has loaded content and AJAX has loaded new content
// (is visible at runtime on form) but can't see them in Browser.Document.All
// or Browser.DocumentText :(
I solved the problem for me.
the key is, attaching a handler for onPropertyChanged
event of the div element which is being populated via ajax call.
HtmlElement target = webBrowser.Document.GetElementById("div_populated_by_ajax");
if (target != null)
{
target.AttachEventHandler("onpropertychange", handler);
}
and finally,
private void handler(Object sender, EventArgs e)
{
HtmlElement div = webBrowser.Document.GetElementById("div_populated_by_ajax");
if (div == null) return;
String contentLoaded = div.InnerHtml; // get the content loaded via ajax
}
这篇关于C#WebBrowser控件 - 获取文档元素的AJAX后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!