Solved

VB6 Classic - Webbrowser control

Posted on 2015-01-12
8
160 Views
Last Modified: 2015-01-13
Hi,

I have two Webbrowser controls (WB1 and WB2) on a form. WB1 fills up with a list of HTML links. When I click a link, I need the resulting page to be displayed in WB2 and not WB1, which is it's default.

Does anyone know a way to prevent WB1 populating, but have WB2 display the selected link's page?

Thanks.
0
Comment
Question by:tvtech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 40546521
You could intercept the Navigate2 event of the first webbrowser, cancel the navigation and redirect to the other webbrowser.

Something like this.
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)

    Cancel = True
    
    WebBrowser2.Navigate URL
    
End Sub

Open in new window

Note if you are navigating to the page with the links in the first browser you'll probably want to add code so when that's happening the above code is ignored.

For example.
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)

    If URL <> "http:\\urloflinkpage.html" Then
        Cancel = True
    
        WebBrowser2.Navigate URL
    End If
    
End Sub

Open in new window

0
 

Author Comment

by:tvtech
ID: 40546554
Sorry. Tried that. If Cancel = True, WB1 will never populate wothe the links and therefore, WB2 won't ever receive any clicks from WB1.
0
 
LVL 33

Expert Comment

by:Norie
ID: 40546591
Did you see my suggestion of checking if WB1 was navigating to the links page and the example code I posted to handle it?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tvtech
ID: 40546615
Yes I did. I tried that code a few days ago, but Cancel = True stops the code and WB2 doesn't run either.
0
 
LVL 33

Expert Comment

by:Norie
ID: 40546741
Did you try this code with the URL that WB1 will initially navigate to instead of 'http:\\urloflinkpage.html'?

Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)

    If URL <> "http:\\urloflinkpage.html" Then
        Cancel = True
    
        WebBrowser2.Navigate URL
    End If
    
End Sub

Open in new window

0
 

Author Comment

by:tvtech
ID: 40546748
Yes. I know to use my own URLs :)
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 40546764
How about this?
Dim boolWB1Ready As Boolean

Private Sub Form_Load()
    WebBrowser1.Navigate "http:\\www.google.com\"
End Sub

Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    If boolWB1Ready Then
        Cancel = True
        WebBrowser2.Navigate URL
    End If
End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    boolWB1Ready = True
End Sub

Open in new window

0
 

Author Comment

by:tvtech
ID: 40546836
You're a legend! My SP was broken. All fixed and code works.

Thanks very much for your help and patience.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question