• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1060
  • Last Modified:

Webbrowser Control - wait till document is complete fully, properly, with frames etc

I have the webbrowser control on  a MSACCESS Form.
I am navigating to an internal webserver.
Each page has many frames.
The problem is my script is running (looking for things in the DOM) before the document is loaded.  I feel it is because a lot of the time only a frame changes.  The URL does not change.

I have read this forum and am aware of http://support.microsoft.com/default.aspx?scid=kb;en-us;180366

Further for example http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20193856.html or http://www.experts-exchange.com/Database/Miscellaneous/Q_21086529.html

I have tried this
Private Sub WebBrowser0_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser0.Object) Then
 do the next thing
end if
end sub
This fires all the time (could this be that the webbrowse is getting the info from the cache

Reading the Microsoft Info in c++ they also give a solution for Frames at the bottom of that page.
I thus declared a public object - being  NAV_OBJ

and had this (NavigateComplete2) was only firing once in my testing but i am aware I need to only get the first object.

Private Sub WebBrowser0_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
     Set pDisp = NAV_OBJ
End Sub

then i had

Private Sub WebBrowser0_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is NAV_OBJ) Then
 do the next thing
end if
end sub

As far as I can work out these two objects never were equal

Also once getting the above solved I assume we will put into the above something like
if success downloadcomplete = true

and then to wait in a sub routine this

do while not downloadcomplete
doevents
loop

For me MSAccess just sits in this loop and does nothing else and will not let the DocumentComplete to fire inorder to change the value of downloadcomplete.



<+++++++++++++++++++++MY TESTING SHOWS++++++++++++++++++++++++edited new information

setting a break on the download complete I can do quite a lot on this website without the break even happening so I need something else.

Is there some way to check that the HTMLDocument or the HTMLFRAME is ready.  I tried Document.readystate = "complete" but that did not seem to work.

Is there some way to track a HTMLDocuments state or a HTMLFrames state and then fire off events relating to that document.


+++++++++++++++++++++++++++
edit: solved it myself as i did not get an answer from this website forum
0
darbid73
Asked:
darbid73
1 Solution
 
MatthiasVanceCommented:
Did you try to check the URL in WebBrowser0_DocumentComplete()?
If it is the URL that you provided on start, the document is fully loaded.

Kind regards,

Matthias Vance
0
 
darbid73Author Commented:
I think the solution to this problem is very specific.

I am dealing with 7 frames here and sometimes one frame was dependant on another.

There are two possible things to do - and I use a combination of both:

First Declare this
Public WithEvents HTMLFRAME4 As HTMLDocument

Then in the document complete routine
Set HTMLFRAME4 = myHTMLDoc.frames(4).Document

Then you will have all of the events of a HTML Document available to you for example I then use

Private Sub HTMLFRAME4_onreadystatechange()

The second thing is that because it appears that some frames were dependant on others at certain times the only way to make sure I did not get errors was to check them all.

for example in my case I checked all the frames and ONLY after all of them are ready do I give the green light.

If myHTMLDoc.frames(1).Document.readyState = "complete" _
And myHTMLDoc.frames(2).Document.readyState = "complete" And myHTMLDoc.frames(3).Document.readyState = "complete" _
And myHTMLDoc.frames(4).Document.readyState = "complete" And myHTMLDoc.frames(5).Document.readyState = "complete" _
And myHTMLDoc.frames(6).Document.readyState = "complete" Then

ALL_FRAMES_COMPLETE = True

Else

ALL_FRAMES_COMPLETE = False
End If

To the above you could add the main document but I found that sometimes my main document did not ever get to a readystate of complete.  I do not know why.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now