473,769 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:loo p while WebBrowser.Busy

do:doevents:loo p until WebBrowser.Read yState = 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 21310
DownloadComplet e Event

"Occurs when a navigation operation finishes, is halted, or fails.
Unlike NavigateComplet e2, 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 "intellisen se" 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.HTMLDocu ment '--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_DocumentComp lete(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:loo p while WebBrowser.Busy

do:doevents:loo p until WebBrowser.Read yState = 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
5928
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
2659
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 to develop. To write each page as an owner drawn control would take ages. The only thing that bothers me is the comminication between the browser control and the main application. We're using the mshtml.dll to hook events
1
2077
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 unattended automated fashion. I have a webbrowser that is created with code but not seen. I found the below code on the internet. It creates a webbrowser, and specifies the URL, which navigates the webbrowser to the page. When the document is...
1
2929
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 unattended automated fashion. I have a webbrowser that is created with code but not seen. I found the below code on the internet. It creates a webbrowser, and specifies the URL, which navigates the webbrowser to the page. When the document is...
0
2847
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 date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. The Refresh method forces the WebBrowser...
0
1584
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 HTML snippets contain <objecttags for ActiveX Control. ActiveX Control loads and works without issue. VB.NET App Architecture: SAME as above except for: The WebBrowser Control is initially seeded by loading HTML from local disk. All Other
6
7549
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 isn't the current directory of the program. What is the current directory? I don't want to use an absolute path, since its contents are saved to disk, and that should always load the css file no matter where it and the css file exists. Titan
4
2623
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 strange thing is that until the page is refreshed with Internet Explorer, the error keeps occurring. I realize no one can debug an application that I can't even provide details about (I didn't write nor do I have access to it) but what difference...
6
3305
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 offscreen buffer then fade this over the exisiting page. Can anyone recommend a good way to approach this? thanks
0
9420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.