DWebBrowserEvents2::DocumentComplete Event
Fires when a document is completely loaded and initialized.
Syntax
void DocumentComplete( IDispatch *pDisp, VARIANT *URL );
Parameters
- pDisp
- [in] A pointer to the IDispatch interface of the window or frame in which the document is loaded. This IDispatch interface can be queried for the IWebBrowser2 interface.
- URL
- [in] A pointer to a VARIANT structure of type VT_BSTR that specifies the URL, Universal Naming Convention (UNC) file name, or a pointer to an item identifier list (PIDL) of the loaded document.
Return Value
No return value.
Event DISPID
DISPID_DOCUMENTCOMPLETEThe DISPID for this event is defined in exdispid.h. Use this value to identify the event handler when implementing IDispatch::Invoke.
Remarks
The value of the URL parameter might not match the URL that was originally given to the WebBrowser Control, because the URL might be converted to a qualified form. For example, if an application specified a URL of www.microsoft.com in a call to the IWebBrowser2::Navigate method or the IWebBrowser2::Navigate2 method, then the URL passed into DWebBrowserEvents2::DocumentComplete is http://www.microsoft.com/. If the server has redirected the browser to a different URL, the redirected URL is passed into the URL parameter.
The WebBrowser Control fires the DWebBrowserEvents2::DocumentComplete event when the document has completely loaded, and the READYSTATE property has changed to READYSTATE_COMPLETE. Following are some important points about the firing of this event.
- In pages with no frames, this event fires one time after loading is complete.
- In pages where multiple frames are loaded, this event fires for each frame where the DWebBrowserEvents2::DownloadBegin event has fired.
- This event pDisp parameter is the same as the IDispatch interface pointer of the frame in which this event fires.
- In the loading process, the highest level frame, which is not necessarily the top-level frame, fires the final DWebBrowserEvents2::DocumentComplete event. At this time, the pDisp parameter is the same as the IDispatch interface pointer of the highest level frame.
For specific code examples using Microsoft Visual Basic and Microsoft Foundation Classes (MFC), see Knowledge Base article Q180366.
Currently, the DWebBrowserEvents2::DocumentComplete does not fire when the IWebBrowser2::Visible property of the WebBrowser Control is set to false. For more information, see Knowledge Base Article Q259935.
See Also
- 7/30/2011
- jonovos
- 5/6/2011
- Stratcat
Users should note - if the web page does any IFRAME navigation then you'll likely receive the DISPID_DOCUMENTCOMPLETE (e.g. DocumentComplete) event before the browser has finished loading the page. The following is a trace of the dispids that get triggered by navigating to bing.com from blank:about. You'll see clearly that URLs are navigated to after the event has been set (list is in sequence) with IE8 without any non-standard BHO/Add-Ons installed:
Referer:
Url: bing.com/
Unescaped: bing.com/
Status: 0
Disp: 108
Disp: 105
Disp: 108
Disp: 102
Referer:
Url: www.bing.com
Unescaped: www.bing.com/
Status: 0
Disp: 108
Disp: 112
Disp: 112
Disp: 102
Disp: 102
Disp: 105
Disp: 113
***** Navigate Complete: 0x6EFB3C, "http://www.bing.com/"
Disp: 252
Disp: 269[ rest of page loads ... ]
***** Navigate Complete: 0x6847244, http://www.facebook.com/plugins/like.php?&width=400&height=80&layout=standard&show_faces=true&action=like&font=arial&colorscheme=light&href=http%3A%2F%2Fwww.bing.com%3Fssd%3D20110503_0700%26ssh%3DS995825291%26FORM%3DHPFBLK%26mkt%3Den-US%26 Disp: 252
Disp: 105
Disp: 105
Referer: http://www.facebook.com/plugins/like.php?&width=400&height=80&layout=standard&show_faces=true&action=like&font=arial&colorscheme=light&href=http://www.bing.com?sd=20110503_0700&ssh=S995825291&FORM=HPFBLK&mkt=en-US&
Url: static.ak.fbcdn.net/rsrc.php/v1/y-/r/eg_BeaYSu3p.css
Unescaped: static.ak.fbcdn.net/rsrc.php/v1/y-/r/eg_BeaYSu3p.css
Status: 0
Referer: http://www.facebook.com/plugins/like.php?&width=400&height=80&layout=standard&show_faces=true&action=like&font=arial&colorscheme=light&href=http://www.bing.com?ssd=20110503_0700&ssh=S995825291&FORM=HPFBLK&mkt=en-US&
Url: static.ak.fbcdn.net/rsrc.php/v1/yV/r/ecpCmrvFebs.js
Unescaped: static.ak.fbcdn.net/rsrc.php/v1/yV/r/ecpCmrvFebs.js
Status: 0
Disp: 105
***** Document Complete: 0x6847244, "http://www.facebook.com/plugins/like.php?&width=400&height=80&layout=standard&show_faces=true&action=like&font=arial&colorscheme=light&href=http%3A%2F%2Fwww.bing.com%3Fssd%3D20110503_0700%26ssh%3DS995825291%26FORM%3DHPFBLK%26mkt%3Den-US%26"
Disp: 259
Referer: http://www.facebook.com/plugins/like.php?&width=400&height=80&layout=standard&show_faces=true&action=like&font=arial&colorscheme=light&href=http://www.bing.com?ssd=20110503_0700&ssh=S995825291&FORM=HPFBLK&mkt=en-US&
Url: static.ak.fbcdn.net/rsrc.php/v1/yo/r/wFcdvtg8yWA.js
Unescaped: static.ak.fbcdn.net/rsrc.php/v1/yo/r/wFcdvtg8yWA.js
Status: 0
Referer: http://www.facebook.com/plugins/like.php?&width=400&height=80&layout=standard&show_faces=true&action=like&font=arial&colorscheme=light&href=http://www.bing.com?ssd=20110503_0700&ssh=S995825291&FORM=HPFBLK&mkt=en-US&
Url: static.ak.fbcdn.net/rsrc.php/v1/yI/r/S4RgCezpKLl.js
Unescaped: static.ak.fbcdn.net/rsrc.php/v1/yI/r/S4RgCezpKLl.js
Status: 0
Disp: 106
Disp: 102
Referer: http://www.facebook.com/plugins/like.php?&width=400&height=80&layout=standard&show_faces=true&action=like&font=arial&colorscheme=light&href=http://www.bing.com?ssd=20110503_0700&ssh=S995825291&FORM=HPFBLK&mkt=en-US&
Url: static.ak.fbcdn.net/rsrc.php/v1/zk/r/QSupuIwbSa4.png
Unescaped: static.ak.fbcdn.net/rsrc.php/v1/zk/r/QSupuIwbSa4.png
Status: 0
Disp: 104
Disp: 105
Disp: 108
Disp: 102
Disp: 105
Disp: 105
So, as we can see, the last three url navigations occur after the final DocumentComplete event has been fired. The browser does not fire anymore after what you see above. All three of the facebook links on bing.com are sent milliseconds after the event (I have Winsock Send hooked in order to watch the HTTP traffice out of the process). Unfortunately and in short, there does not appear to be a relible method by which to determine when a page has finished loading through IE events... If _close_ is good enough then DocumentClose is probably the best you'll get.
Suggestion: (Microsoft Internal) - IE Test, this check should be in your BVTs as it's very easy to automate and test. I'm sure navigating to msw would exhibit the same behavior as above.
