Results 1 to 5 of 5

Thread: Webbrowser cancel navigation

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Location
    Brisbane
    Posts
    19

    Webbrowser cancel navigation

    Hi

    I have two Webbrowser controls on a form.

    The first control loads and displays a page of links. I need to be able to click a link and have it open its page in the second control, but not the first control, which is its natural action.

    I have tried Cancel = True in BeforeNavigate, but that prevents the links page from opening at all.

    Does anyone have a better way to make this work?

    Thanks.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Webbrowser cancel navigation

    Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'VB6 and earlier' forum

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Webbrowser cancel navigation

    Code:
    Private WithEvents NewWebBrowserWindowHandler As SHDocVwCtl.WebBrowser_V1
    
    Private Sub Command1_Click()
     WebBrowser1.Navigate "www.vbforums.com"
    End Sub
    
    Private Sub Form_Load()
     Set NewWebBrowserWindowHandler = WebBrowser1.Object 'Your webrowser control comes here..
    End Sub
    
    Private Sub NewWebBrowserWindowHandler_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Processed As Boolean)
     WebBrowser2.Navigate URL
    
     'Tell the control, your code has processed the event, 
     'there's no need to open the new window
     Processed = True 
    End Sub


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    New Member
    Join Date
    Feb 2018
    Posts
    10

    Re: Webbrowser cancel navigation

    Quote Originally Posted by jmsrickland View Post
    Code:
     ...
     Processed = True 
    End Sub
    This is an old thread (but not compared to most VB6 threads), but I was scouring the Web for help with the same problem.

    At first glance, I didn't understand how "Processed = True" on its own could do anything. As far as I could tell, "Processed" is some undeclared variable. But I tried it anyhow and sure enough, it didn't do anything. What am I missing there?

    Anyway, my problem came when I was intercepting the call to open the file in BeforeNavigate2 (an odd name since there is no BeforeNavigate1 that I can find), calling a sub in my program to bring up the second WebBrowser and open the ULR in it, then using Cancel=True to keep the first browser from changing, but the program was locking up there until I did a Ctrl-Break and then it finished. Eventually, I tried adding
    Code:
    [2nd browser window].Refresh
    DoEvents 
    Cancel = True
    and it worked fine.

  5. #5
    New Member
    Join Date
    Feb 2018
    Posts
    10

    Re: Webbrowser cancel navigation

    Quote Originally Posted by jmsrickland View Post
    Code:
     ...
     Processed = True 
    End Sub
    This is an old thread (but not compared to most VB6 threads), but I was scouring the Web for help with the same problem.

    At first glance, I didn't understand how "Processed = True" on its own could do anything. As far as I could tell, "Processed" is some undeclared variable. But I tried it anyhow and sure enough, it didn't do anything. What am I missing there?

    Anyway, my problem came when I was intercepting the call to open the file in BeforeNavigate2 (an odd name since there is no BeforeNavigate1 that I can find), calling a sub in my program to bring up the second WebBrowser and open the ULR in it, then using Cancel=True to keep the first browser from changing, but the program was locking up there until I did a Ctrl-Break and then it finished. Eventually, I tried adding
    Code:
    [2nd browser window].Refresh
    DoEvents 
    Cancel = True
    and it worked fine.

Tags for this Thread

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