• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5367
  • Last Modified:

VB.NET webbrowser - force popup window to navigate in the same window

I have a webbrowser control. If I click on a popup window of a webpage that is loaded, I want the new window event to be canceled and the webbrowser should just navigate to the target URL of the new window within the webbrowser control of my app.

I found this resource, yet can not make sense of it.

Is there some example code?
0
wfskmoney
Asked:
wfskmoney
1 Solution
 
kristof1104Commented:
Just made a test proj here is the code:

Public Class Form1

    Dim url As String = ""

    Private Sub WebBrowser1_NewWindow(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
        e.Cancel = True
        WebBrowser1.Navigate(url)
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("file://C:\Users\kve\Desktop\bla.html")

    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim links As HtmlElementCollection = WebBrowser1.Document.Links
        For Each var As HtmlElement In links
            var.AttachEventHandler("onclick", AddressOf LinkClicked)
        Next
    End Sub

    Private Sub LinkClicked(sender As Object, e As EventArgs)
        Dim link As HtmlElement = WebBrowser1.Document.ActiveElement
        url = link.GetAttribute("href")
    End Sub
End Class

Open in new window


I can also upload the project for you if you want
0
 
ArkCommented:
For Each var As HtmlElement In links
Your need check ALL elements onclick events as well - it can point to javascript:window.open()
BTW, for links you can use following dirty trick:
Private Sub WebBrowser1_NewWindow(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
        e.Cancel = True
        WebBrowser1.Navigate(WebBrowser1.StatusText)
    End Sub

Open in new window

:)
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
wfskmoneyAuthor Commented:
The javascript workarounds do not work for sites that use other methods to open pop up windows.

For my project, I have an inline browser where users can donate to savethechildren.com

However, for checking that the user has successfully donated, I need to keep the paypal button popup inside the webbrowser control. If the paypal buttons opens a new window, I can not access the content of the landing page after the donation.

I managed to build a project where popups are opened in a second tab (a new webbrowser object is created for that).

It works for normal popups but not for paypal buttons. You can test it by clicking on the paypal button of the site that loads. Anyone have an idea?

NewWindowinBrowserControl
0
 
ArkCommented:
See VB version of extended webbrowser:
http://code.bn2vs.com/viewtopic.php?t=83
0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now