?
Solved

VB6 Classic - Webbrowser control

Posted on 2015-01-12
8
Medium Priority
?
166 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 34

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 34

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
Independent Software Vendors: 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 34

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 34

Accepted Solution

by:
Norie earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Suggested Courses

771 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