Solved

VB6 Classic - Webbrowser control

Posted on 2015-01-12
8
155 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:tvtech
Comment Utility
Yes I did. I tried that code a few days ago, but Cancel = True stops the code and WB2 doesn't run either.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 33

Expert Comment

by:Norie
Comment Utility
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
Comment Utility
Yes. I know to use my own URLs :)
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
Comment Utility
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
Comment Utility
You're a legend! My SP was broken. All fixed and code works.

Thanks very much for your help and patience.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now