Results 1 to 7 of 7

Thread: BeforeNavigate2 (how) does it work??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    78

    Question BeforeNavigate2 (how) does it work??

    Hi all,

    In vb.net I have my Axwebbrowser control and I added a beforenavigate2 sub to my code so that I could capture some things (eg the last button the user clicked on) just before the current webpage disappears and a new webpage is loaded. However this does not seem to work and I cannot even get it to go into the beforenavigate2 sub (i put a msgbox in the subs first line and it never has been displayed).

    I guess I am using the beforenavigate2 wrongly? If so how do I use it? Or better still how can I get a sub to be called just before a new webpage is loaded in the webbrowser?

    EG.

    I'm at yahoo.com.
    I enter some words in the search engine textbox.
    I click search.
    This click is the last thing the user can do before the next page is displayed.
    I want to call a sub at this point, after the last click and before the next page is loaded.

    Any ideas guys?

    I thought beforenavigate2 was the answer.
    It doesn't seem to be.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    beforenavigate2 has a known problem ( not working lol ) but here's a fix i just slapped together for you :
    VB Code:
    1. Private WithEvents doc As SHDocVw.DWebBrowserEvents_Event
    2. '/// handle all browser events through doc now not brWeb.
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         Dim b As Object = brWeb.Application
    6.         doc = DirectCast(b, SHDocVw.WebBrowser_V1)
    7.     End Sub
    8.  
    9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    10.         brWeb.Navigate("http://google.com")
    11.     End Sub
    12.  
    13.     Private Sub doc_BeforeNavigate(ByVal URL As String, ByVal Flags As Integer, ByVal TargetFrameName As String, ByRef PostData As Object, ByVal Headers As String, ByRef Cancel As Boolean) Handles doc.BeforeNavigate
    14.         MessageBox.Show(URL)
    15.     End Sub
    hope it helps.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    78
    Cheers dynamic_sysop, that's sure to help

    One other thing though the doc doesn't have a documentComplete
    the webbrowser does.
    Is it ok to use the webbrowsers documentComplete?
    If not does the downloadComplete do the same job, cos doc has one of them ?

    I need the docComplete so that I can load a webpages HTML source once the (visual) page has totally loaded.

    Cheers for your help dynamic_sysop

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    use the doc's document_Complete
    all the events you need are covered by doc
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    78
    Please say you mean use the doc's download_complete

    This is ok with webpages with frames isant it? It won't go triggering until all the frames are loaded will it? I guess it doesn't matter as long as it still triggers when the whole thing (all frames) are loaded!

    Cheers for all you help dynamic_sysop

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    VB Code:
    1. Private WithEvents doc As SHDocVw.DWebBrowserEvents_Event
    2.     '/// doc will handle all the events for brWeb now...
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim b As Object = brWeb.Application
    5.         doc = DirectCast(b, SHDocVw.WebBrowser_V1) '///set doc as the active handler for brWeb's events.
    6.     End Sub
    7.  
    8.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    9.         brWeb.Navigate("http://google.com") '///lets navigate to a website.
    10.     End Sub
    11.  
    12.     Private Sub doc_BeforeNavigate(ByVal URL As String, ByVal Flags As Integer, ByVal TargetFrameName As String, ByRef PostData As Object, ByVal Headers As String, ByRef Cancel As Boolean) Handles doc.BeforeNavigate
    13.         MessageBox.Show(URL) '/// check that before navigate now works.
    14.     End Sub
    15.  
    16.     Private Sub doc_StatusTextChange(ByVal [Text] As String) Handles doc.StatusTextChange
    17.         Label1.Text = Text '///show the status text in a label.
    18.     End Sub
    19.  
    20.     Private Sub doc_TitleChange(ByVal [Text] As String) Handles doc.TitleChange
    21.         MyBase.Text = Text '/// set the form's caption to the current url
    22.     End Sub
    23.  
    24.     Private Sub doc_DownloadComplete() Handles doc.DownloadComplete
    25.         MessageBox.Show(brWeb.LocationURL & "   is now complete!")
    26.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    78
    You are most helpful

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