I want to create a simple Userform with a WebBrowser object in PowerShell to browse one specific URL. The website located at that URL opens some hyperlinks as popups which causes these links to open in a new InternetExplorer window.
Instead I would like to catch these popups with the NewWindow-event and somehow create another tab with a new WebBrowser instance.
First of all I'm stuck at firing the event correctly it seems. The following code runs fine so far, but the event won't get fired at the right time. Instead I get multiple notification popups after I close my userform (number depending on how many new windows I opened).
$Browser_NewWindow = {
$(New-Object -ComObject WScript.Shell).Popup("Event fired correctly")
}
$Form = New-Object System.Windows.Forms.Form
$Browser = New-Object System.Windows.Forms.WebBrowser
$Form.Text = "MiniBrowser"
$Form.Controls.Add($Browser)
Register-ObjectEvent -InputObject $Browser -EventName NewWindow -Action $Browser_NewWindow
$Browser.Navigate("http://www.bing.com")
$Form.Width = 900
$Form.Height = 900
$Browser.Top = 0
$Browser.Left = 0
$Browser.Width = 880
$Browser.Height = 890
$DialogResult = $Form.ShowDialog()