Results 1 to 11 of 11

Thread: Webbrowser Wait!

  1. #1
    rsitogp
    Guest

    Talking Webbrowser Wait!

    Well I've had this problem alot but I worked around, but now it's really getting to me, I use the webbrowser control, navigate to a page and want to do something after it loads but not before it's done. I use the DocumentComplete event but the webbrowser goes to it before the page is done loading. I thought of using the webbrowser.statustext but it has it's own problems.

    Anyone have an idea?
    Thanks in advance!

  2. #2
    Knele
    Guest
    well I would like to know this too...
    I got an idea how to do it, but I'm not sure if it will work and how to do it.
    Can't you examine the source of the page and look for the </html> tag? if it's there, the file should be downloaded completely, or am I wrong? Please let me know if this works and how you did it, cause I really need this in my App...

  3. #3
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Use the NavigateComplete2 event.

  4. #4
    rsitogp
    Guest
    Doesn't the NavigateComplete2 occour before the page has loaded?
    Originally posted by seoptimizer2001
    Use the NavigateComplete2 event.

  5. #5
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    No, if you use the Download_Complete the webbrowser will still be busy. Use Navigate_Complete2

  6. #6
    Matthew Gates
    Guest
    You could also try something like:


    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     WebBrowser1.Navigate "http://www.vb-world.net"
    4.  
    5.     Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
    6.         DoEvents
    7.     Loop
    8.  
    9.     Msgbox "We are here! Hope you enjoyed the ride!", 64
    10.  
    11. End Sub

  7. #7
    Knele
    Guest
    navigate_complete2 doesn't work...

  8. #8
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    You may be a victim of REDIRECTION or multiple frames. DocumentComplete works for me if
    Code:
    Private Sub WebBrowser1_DocumentComplete( _
        ByVal pDisp As Object,  URL As Variant)
        ' Process if whole page is done not just a frame
        If Not (pDisp Is WebBrowser1.object) Then Exit Sub
        '*****
        '* Ready State must be interactive or complete
        '*****
        Select Case WebBrowser1.ReadyState
        Case READYSTATE_INTERACTIVE, READYSTATE_COMPLETE
            Handler.DocumentComplete
        End Select
    ......
    "Handler
    Dim objElements     As Object
    Dim objElement      As Object
    Do
        With mobjWeb
            
            Set mobjDocument = mobjWeb.Document
            If Err.Number <> 0 Then Exit Do
            If mobjDocument Is Nothing Then Exit Do
    
            '*****
            '* META http-equiv="Refresh" BYPASS REDIRECTION
            '*****
            Set objElements =  _
                mobjDocument.getElementsByTagName("Meta")
            If Err.Number <> 0 Then Exit Do
            If objElements Is Nothing Then Exit Do
            For Each objElement In objElements
                If LCase(objElement.httpEquiv) = "refresh" Then
                    '* We are still busy
                    blnBusy = True
                    Exit Do
                End If
            Next
            If Err.Number <> 0 Then Exit Do
    Last edited by John Yingling; Jun 28th, 2001 at 10:55 AM.

  9. #9
    rsitogp
    Guest
    Thanks for helping, John Yingling - could you simplify it a bit for us simpletons?

  10. #10
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    If the site you reach with your NAVIGATE request decides to redirect you to another URL you can receive two pages. First the page that contains just enough HTML to include a META tag with a "Refresh" request to a new URL. Navigation events start all over again for the new URL. When you get to your final destination, the site may send an HTML page with frames so there is a DOCUMENT_COMPLETE event for each frame and finally for the page.

    I have put my page handling into class which has been a property that contains the FORM object and "shadow" events for the Webbrowser. It does not use DoEvents but rather reacts to the WebBrowser events. In theDocument_Complete event I ignore the redirection and exit. The next page is comimg automatically. As each DOCUMENT_COMPLETE occurs I fill in various data, set a variable to tell me what page to process next, "click" to get the next page and exit.

    I fought through the DHTML info in Web Development at http://www.msdn.microsoft.com / MSDN / Programming and Reusing the Browser and Web Page Development and
    http://www.w3.org/TR/REC-DOM-Level-1...-one-html.html

  11. #11
    Hyperactive Member
    Join Date
    May 2002
    Posts
    434
    I found this in the MSDN help file. Check out the example code at the bottom. It worked for me:

    DocumentComplete Event

    Occurs when the document that is being navigated to reaches the READYSTATE_COMPLETE state.

    Syntax
    Private Sub object_DocumentComplete(ByVal pDisp As Object, URL As Variant)

    Value Description
    object An object expression that evaluates to an object in the Applies To list.

    pDisp An object that evaluates to the top-level or frame WebBrowser object corresponding to the event.

    URL A string expression that evaluates to the URL, UNC file name, or PIDL that was navigated to. Note that this URL can be different from the URL that the browser was told to navigate to. One reason is that this URL is the canonicalized and qualified URL; for example, if an application specified a URL of "www.microsoft.com" in a call to the Navigate or Navigate2 method, the URL passed by DocumentComplete will be "http://www.microsoft.com/". Also, if the server has redirected the browser to a different URL, the redirected URL will be reflected here.


    Remarks

    For a document without frames, this event will fire once when the document is finished loading. On a document containing multiple frames, this event is fired once for each frame. When the multiple-frame document has finished loading, the top-level frame fires the event one final time. To detect the last DocumentComplete event of a multiple-frame document, compare the pDisp object returned from the event to the WebBrowser object itself. The following example indicates how to trap the final DocumentComplete event.
    Code:
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        If (pDisp Is WebBrowser1.Object) Then
            Debug.Print "Document is finished loading."
        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
  •  



Click Here to Expand Forum to Full Width