?
Solved

WebBrowser Control and the NewWindow2 event

Posted on 2006-04-28
8
Medium Priority
?
725 Views
Last Modified: 2013-12-25
My webbrowser control loads a page from a secure site. Some of the popup links on that page are located within that site and I must load them in a new instance of the webbrowser or I will be presented with another logon dialogue. Other links are off site (unsecured) and can be opened in a new instance of IE. My preference would be to open all popup links in IE.

My question is, how can I determine which link has been clicked before the NewWindow2 event? The BeforeNavigate2 is not called before a popup window. Even better would be to pass all popup windows to IE but I can't figure out how to do this without receiving a logon dialogue.
0
Comment
Question by:dbalman
  • 4
  • 4
8 Comments
 
LVL 17

Expert Comment

by:vb_elmar
ID: 16563748
Can you post the URL of the site?
0
 

Author Comment

by:dbalman
ID: 16564200
No, it's internal.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 16564400
In order to get an answer for this question it would be helpful, if we get the link
of a comparable http site, because this is a VB expert forum (not a html expert forum).
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:dbalman
ID: 16565224
This is not a HTML question. Please reread the question. If further clarification is required then please ask.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 16565359
When writing a code for your problem, a sample http site would be helpful for testing purposes. At this
moment, a testing site is not available, therefore i would need to program the testing site by myself (e.g. with
frontpage). But to write a site by myself is too time-consuming for me.
0
 

Author Comment

by:dbalman
ID: 16565698
Maybe this will help.  I need the URL being navigated to before the NewWindow2 event.


Private Sub Form_Load()

WebBrowser1.Navigate2 "About: Blank"

WebBrowser1.Document.write "<A href=""http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/"" target=_blank>http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/</A><DIV></DIV><A href=""http://www.google.com/""target=_blank>http://www.google.com</A>"
 
End Sub

I can't provide a secure link as that would entail providing the account to access that site also. I will max the points if someone does figure out how to open https popups (located in a webbrowser control) in IE.

Thanks
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 750 total points
ID: 16567440
This sample needs:
1 button
1 webbrowser control


1.
On a form, add a webbrowser1 control (CTRL-T \ "Microsoft Internet Controls")

2.
Go to the VB toolbox, and  click on the blue globe icon. Paste
the MSIE ActiveX Control onto the form.

3.
-Paste the code below into your Form.

4.
Run it.



'*************************************
'Form Code:
'*************************************

Private Sub Command1_Click()
    WebBrowser1.Navigate "about:blank"
Call wait_4_navigate
    zz = ""
    zz = zz & "<A href='http://whatismyip.com' target=_blank>target1</A>"
    zz = zz & "<br>"
    zz = zz & "<br>"
    zz = zz & "<A href='http://spotlight.de/zforen/mvb/m/mvb-1146230885-13311.html' target=_blank>target2</A>"
    WebBrowser1.Document.write zz
End Sub


Private Sub Form_Load()
    BackColor = RGB(166, 166, 144)
    Move 0, 0, Screen.Width * 0.98, Screen.Height * 0.94
    Command1.Move 0, 0
    WebBrowser1.Move 0, Command1.Height * 2, Width * 0.95, Height * 0.8
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)
    Caption = URL
    If Len(URL) > 8 Then Caption = URL
    If URL = "http://whatismyip.com/" Then
        Cancel = True
        'WebBrowser1.Navigate "about:blank"
        'Call wait_4_navigate
        a = MsgBox("close this webbrowser window ?", 4, "blocked: whatismyip.com")
        If a = vbYes Then Visible = 0
    End If
End Sub


Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    Dim f       As New Form1
   
    f.WebBrowser1.RegisterAsBrowser = True
    Set ppDisp = f.WebBrowser1.Object
    f.Visible = True
End Sub


Sub wait_4_navigate()
    Do
    a = WebBrowser1.ReadyState
    If a <> myState Then myState = a: Me.Caption = Me.Caption & "      readystate-->:" & a
    DoEvents
    Loop While a <> myState Or a <> 4
   
    Caption = Caption & "      ***READY***"
End Sub

0
 

Author Comment

by:dbalman
ID: 16568960
At first I couldn't figure out why your solution was firing the forms NewWindow2 event and mine wasn't. It then it occurred to me that I am using a separate form and webbrowser to handle pop-ups. I need to watch its NewWindow2 event then I can send it to IE or a new pop-up form. I overlooked the obvious and I appreciate your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

850 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