?
Solved

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

Posted on 2009-04-23
2
Medium Priority
?
1,049 Views
Last Modified: 2013-11-19
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
Comment
Question by:darbid73
2 Comments
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 24343404
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
 
LVL 20

Accepted Solution

by:
darbid73 earned 0 total points
ID: 24535357
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question