DownloadComplete Event
"Occurs when a navigation operation finishes, is halted, or fails.
Unlike NavigateComplete2, which is fired only when a URL is
successfully navigated to, this event is always fired after a
navigation starts. "
If you have trouble finding info. for the WB properties,
methods and events you can look up IE and the IE Document
Object Model (DOM). The WB is just an IE window, so IE object
properties are generally the same as for the WB and IE DOM
applies to the WB document.
Also, you can reference the MSHTML.tlb library
("Microsoft HTML Object Library") and then
access the entire DOM through "intellisense" if that's helpful.
(It may apply to your question about webpage option buttons.
Everything on the page is available through the DOM.
If necessary you can always access page elements through
the "all" collection. Each item in all is an element. If you look
up IHTMLElement in MSDN you'll see how many things
you can "get/let" once you get hold of an Element object.
The Element properties are the HTML attributes. Anything
you can't reach from there is usually accessible through the
Element.Style property, which gives you access to all style
sheet attributes for the element.)
'-- declare document and Body objects:
Private WithEvents Doc As mshtml.HTMLDocument '--document object.
Private BodyOb As HTMLBody '-- BODY object.
'-- when a new document is created, set it to Doc object.
'-- This only works properly in IE5+.
'--
'-- (In IE 4: You have to
'-- hook the browser window with each document load.
'-- The actual document window is new for each document,
'-- so it has to be re-hooked, and before that it has to be
'-- re-found(!) because it's about 4 windows down in the
'-- window hierarchy. Then, still, the IE4 DOM doesn't always
'-- work properly.)
'-- Doc object is set when document finishes loading:
Private Sub WB_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set Doc = Nothing
If Not WB.document Is Nothing Then
Set Doc = WB.document
Set BodyOb = Doc.body '-- can also set BODY object if desired
'-- to reduce
references in code.
end if
End Sub
You can then write subs for document events like:
Private Function Doc_onclick() As Boolean
I've been using the following 2 ways to make sure my WebBrowser is
finished loading a page before continuing with the next code.
do:doevents:loop while WebBrowser.Busy
do:doevents:loop until WebBrowser.ReadyState = STATE_COMPLETE (or
something like that. I don't have the code in front of me)
But, for some reason, occasionally the code continues past the loops even
though the page hasn't finished loading causing an error. I've started
using both lines one after the other and that seems to solve the problem, but it
seems like there should be a better way.
So, what's the best way to make sure the page is finished loading?