|
-
Jun 19th, 2001, 08:54 PM
#1
Thread Starter
Frenzied Member
Help! Doing an action if a webbrowser navigate fails..
If an error occurs in a webbrowser, like "Page cannot be displayed", "File Not Found", etc, how can i refresh the webbrowser?
Also, lets say i have the code:
-----------------------------------------------
Webbrowser1.Navigate website
do
doevents
loop until webbrowser1.busy = false
webbrowser1.document.links(12).click
do
doevents
loop until webbrowser1.busy = false
webbrowser1.Navigate website2
-----------------------------------------------
If any part of that code takes too long to load (20 seconds), how can i make it so it will redo that particular code? for example, if the link takes more than 20 seconds to load, it will reclick it.
This is a major problem with filling forms, because if youre in a loop to submit 5 or so forms, and it takes too long to submit to a site, the rest of the code gets very screwed up. Usually, the webbrowser just doesnt submit (locks) to a form if its moving too fast, and this can easily be fixed if the submit button is reclicked.
So, if anyone knows the solution to this dillemma, please reply
-
Jun 19th, 2001, 09:11 PM
#2
if webbrowser1.locationname = "Cannot find server" then webbrowser1.refresh
or try
webbrowser1.goBack
webbrowser1.goforward
not exactly positive that it will work put the code in the download complete or use a timer to give you a timeout of say 30 sec then call the refresh
hope it helps
-
Jun 19th, 2001, 09:36 PM
#3
Frenzied Member
Just a suggestion....I would put all your code that deals with filling in forms in the DocumentComplete Event. The reason I suggest this, is because this is the ideal time to interact with the Document (web-page). Also you can't do anything like programatically filling in a form on a web-page until it has completely finished loading, which is when the DocumentComplete Event is triggered. You would also be able to get rid of all your loops as they would no longer be necessary.
All you need to do is base everything on the WebBrowser1.LocationURL....something like this:
Code:
If (pDisp Is WebBrowser1.Object) Then
If WebBrowser1.LocationURL = "http://www.website.com" Then
WebBrowser1.document.links(12).click
Else If WebBrowser1.LocationURL = "http://www.website2.com" Then
WebBrowser1.document.links(6).click
End If
End If
All you would need is some code for a command button to get everything started - WebBrowser1.Navigate "http://www.website.com"
If you want to refresh a error page then try checking for the WebBrowser1.LocationName in the DocumentComplete Event. If it equals "File Not Found" or whatever then do a WebBrowser1.Refresh
-
Jun 19th, 2001, 10:46 PM
#4
Frenzied Member
I think there is an ondownload complete event for the webbrowser control. So that will fire when the page has completly loaded. Then you can compare that. I am not sure if there is a const or something for that. But atleast this way it will cut the doevents.
-
Jun 20th, 2001, 01:34 AM
#5
Thread Starter
Frenzied Member
what about this part?
If any part of that code takes too long to load (20 seconds), how can i make it so it will redo that particular code? for example, if the link takes more than 20 seconds to load, it will reclick it.
This is a major problem with filling forms, because if youre in a loop to submit 5 or so forms, and it takes too long to submit to a site, the rest of the code gets very screwed up. Usually, the webbrowser just doesnt submit (locks) to a form if its moving too fast, and this can easily be fixed if the submit button is reclicked.
Thx
-
Jun 20th, 2001, 08:26 AM
#6
Hyperactive Member
DownloadComplete is really misnamed. It fires after navigation begins. I believe it only means that the web site has been contacted. The complete document is not available until DocumentCXomplete and DocumenyComplete fires for each frame and the document. A document with two frames will fire three times. Go to www.msdn.microsoft.com Libraries / Web Workshop / Reusing Browser / Reference for VB.
Using a Timer and the WebBrowser Events is the way to go.
Code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,
URL As Variant)
If (pDisp Is WebBrowser1.Object) Then
Debug.Print "Web document is finished downloading"
End If
End Sub
-
Jun 20th, 2001, 08:30 AM
#7
for future reference:
Good loop code to wait till the doc is complete...
Do Until Webbrowser1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
I would say..have something the Document complete event that resets the timer also. So when its done loading the timer goes back to 20 seconds.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 20th, 2001, 08:41 AM
#8
Frenzied Member
Yeah you are right. I was just remembering off the top of my mind.
Originally posted by John Yingling
DownloadComplete is really misnamed. It fires after navigation begins. I believe it only means that the web site has been contacted. The complete document is not available until DocumentCXomplete and DocumenyComplete fires for each frame and the document. A document with two frames will fire three times. Go to www.msdn.microsoft.com Libraries / Web Workshop / Reusing Browser / Reference for VB.
Using a Timer and the WebBrowser Events is the way to go.
Code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,
URL As Variant)
If (pDisp Is WebBrowser1.Object) Then
Debug.Print "Web document is finished downloading"
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|