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.
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
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
Re: Webbrowser cancel navigation
Quote:
Originally Posted by
jmsrickland
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.
Re: Webbrowser cancel navigation
Quote:
Originally Posted by
jmsrickland
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.