开发者

Winforms web browser control not firing document complete with AJAX web site

The VB.Net desktop app uses the IE browser control to navigate the web. When a normal page loads the document_complete event fires and I can read the resulting page and go from there. The issue I am having is that the page I am driving is written with AJAX, so the document complete event never fires. Furthermore, when you view the source of the page after it loaded a new portion via AJAX, it hasn't change. How are people开发者_开发知识库 handling this? What are my options?


This solution might solve your problem. prerequists: AxwebBrowser control, reference to mshtml.dll

Dim axmshtml As mshtml.HTMLDocument = YourAxWebBrowserControl.Document

Dim HTMLSource As String = axmshtml.body.innerHTML 'html source, including DOM changes

If you know what you are looking for you can put the above code in a timer/loop
and simply monitor the page source for changes.


If wb is your webbrowser control, then instead of getting the HTML by using:

wb.DocumentText

use:

wb.Document.Body.InnerHtml

This will give you the updated html, reflecting the AJAX update.

As to detecting when the AJAX completes, for me it seems to be triggering a DocumentCompleted event. Not sure why it's different for you.


You need to interact with the Javascript code in the website using the methods on HtmlDocument.


I have seen this kind of behavior with C# when some AJAX scripts created a race condition. Adding the defer attribute to the script tag helped in that case. YMMV.


Not sure if this will work.

When the Ajax call completes, add a random anchor hash to the URL like so: foo.html#23234 then add your code to the NavigateComplete2 event.

http://msdn.microsoft.com/en-us/library/aa768334%28VS.85%29.aspx


I'm guessing that the page your load in your windows app does an AJAX call, which appears to refresh the page. In that case, the document_complete event isn't fired, because the webpage itself isn't refreshed, but a portion of the page.

I found a similar question about this problem, with an accepted answer in VB.Net.


You can use the ProgressChanged event, it seems to fire during ajax calls

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜