stopping popup windows in a web browser
Leader)


posts: 1481
since: Apr 8, 2001
from: Shropshire, England
http://www.vbcity.com/forums/topic.asp?tid=22075&highlight=beforenavigate&page=2
Hi,
As most 'unwanted' pop-ups occur during the 'OnLoad' event of the Body element, you can expand on cancelling the NewWindow by determining whether the document being loaded has completed:
Code:
Cancel =
Debug.Print
Cancel =
Debug.Print
Debug.Print
WebBrowser1.Silent =

I'm not sure how you can get the NewWindow's target URL without allowing the new window to open.
The code will redirect any Target="_blank" type navigation to the original window, but will allow user-activated links that are script based to open in a new window - this would probably be the point at which to implement a new form and RegisterAsBrowser code. An example is the 'Comment' link in a Microsoft KB article which uses javascript to open the target window.
Code:
sLink = WebBrowser1.Document.parentWindow.event.srcElement.href
Debug.Print & sLink
Cancel =
WebBrowser1.Navigate sLink
Debug.Print
Cancel =
sLink = WebBrowser1.Document.activeElement.href
Cancel =
Debug.Print & sLink
Cancel =
WebBrowser1.Navigate sLink
Debug.Print
Cancel =
Cancel =
Hope that helps
