Solved

VB6 Classic - Webbrowser control

Posted on 2015-01-12
8
158 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

821 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