473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I make sure WebBrowser page is finished loading

BKM
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?
Jul 17 '05 #1
1 21251
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?

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
I am at my wits' end. I have the following code: WebBrowser1.Navigate ("c:\path\page.htm") Text1.Text = WebBrowser1.Document.Links.length Where the page.htm has the following HTML: <html>
1
by: boxim | last post by:
Hi All, Just after some other opinions really.... We're writing this application that in places implements the WebBrowser control to make certain bits look nicer as well as make things quicker...
1
by: eskildb | last post by:
First, please be gently. I am fairly new to the programming world (1.5 years with some expermentation prior to). I have been working on a project that has to print HTML pages with graphics in a...
1
by: eskildb | last post by:
First, please be gently. I am fairly new to the programming world (1.5 years with some expermentation prior to). I have been working on a project that has to print HTML pages with graphics in a...
0
by: cweeks | last post by:
>From the MSDN documentation for WebBroswer.Refresh(): "The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration...
0
by: Mark | last post by:
I am converting a VB6/COM application to VB.NET and must remove all COM objects. VB6/COM App Architecture: Windows Form hosts WebBrowser which loads HTML snippets from local disk. Some of the...
6
by: titan.nyquist | last post by:
The WebBrowser control won't load a css file written in the same directory as the program. If I put an absolute path to it, it will load it. Thus, the current directory of the WebBrowser control...
4
by: David | last post by:
I'm using the AxSHDocVw.WebBrowser control to download data from a webpage at work (it's an internal page on my company's intranet). The page produces a runtime error after a while and the...
6
by: Martin Slater | last post by:
Hi all, I'm using a webbrowser control within an application for the UI and want to hide the flicker and redraw when changing pages. Ideally I want to render the new page to a seperate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.