IWebBrowser2: how to force links to open in new window?

Posted by Rob McAfee on Stack Overflow See other posts from Stack Overflow or by Rob McAfee
Published on 2010-05-27T21:54:59Z Indexed on 2010/05/28 8:31 UTC
Read the original article Hit count: 258

The MSDN documentation on WebBrowser Customization explains how to prevent new windows from being opened and how to cancel navigation. In my case, my application is hosting an IWebBrowser2 but I don't want the user to navigate to new pages within my app. Instead, I'd like to open all links in a new IE window. The desired behavior is: user clicks a link, and a new window opens with that URL.

A similar question was asked and answered here and rather than pollute that answered post, it was suggested I open a new discussion.

The members on the related post suggested I should be able to do this by trapping DISPID_BEFORENAVIGATE2, setting the cancel flag, and writing code to open a new window, but I've found out that the browser control gets lots of BeforeNavigate2 events that seem to be initiated by scripts on the main page. For example, amazon.com fires BeforeNavigate2 events like crazy, and they are not a result of link invocation.

Replies appreciated!

© Stack Overflow or respective owner

Related posts about c++

Related posts about internet-explorer