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
Solved

VB6 Classic - Webbrowser control

Posted on 2015-01-12
8
159 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 - Convert HH:MM into Decimal 8 62
clicking a shape in a frame array vb6 3 46
Export Data to Different .csv Files 26 114
Dinamic report to Crosstab query 9 33
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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