1

I have IWebBrowser2 ctrl embedded into my own dialog. I want to simply display a promo banner within it from my url. How to disable all popup menu items from the control and force it to open links in new window (currently when I click on link in the banner, it is being opened within the same control). Regards Dominik

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
cubesoft
  • 3,448
  • 7
  • 49
  • 91

2 Answers2

2

I don't know if there is a more convenient way of doing this - but you could always intercept BeforeExplorerNavigate2(), set the out-parameter cancel to true and from there either do a new Navigate() with a different target frame name or open a new window.

As Rob pointed out, there might be problem with filtering out navigate events originating from scripts, see this question.

Community
  • 1
  • 1
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • How to register for IWebBrowser2 events? I have only IWebBrowser2 object. – cubesoft Sep 22 '09 at 15:59
  • You implement DWebBrowserEvents2 and register as an event sink for this. Through Remys article you'll find the NewWindow3() event, which should give you what you need. – Georg Fritzsche Sep 23 '09 at 02:11
  • Ok. Thanks, I've found it althought in WTL it is not as easy as in MFC. – cubesoft Sep 30 '09 at 10:22
  • Georg, see my comment above-- this question is still not answered. I'm trying to do this same thing and so far I have yet to find a reliable solution. The key problem with trapping DISPID_BEFORENAVIGATE2 is that you can't tell if it's user-initiated or script-initiated. – Rob McAfee May 25 '10 at 23:15
  • @Rob: Obviously the question was answered for the OP... Anyway, you can identify the frame from which the request originated via the `pDisp` parameter - if you don't know how open a new question about it. – Georg Fritzsche May 26 '10 at 05:43
  • Thanks Georg! I didn't mean to imply the answers weren't helpful for the OP, but the question is interesting to more than just the OP. This post is one of the top hits on Google and it would be great if there were a complete answer for the other hundreds of programmers researching the issue. pDisp doesn't help. With some URLs e.g. Amazon you'll get BeforeNavigate2 events for scripts and user events on the same frame. IHlinkFrame may work: http://msdn.microsoft.com/en-us/library/aa767939%28v=VS.85%29.aspx – Rob McAfee May 26 '10 at 22:14
  • @Rob: Alright, you could have mentioned that right away, i didn't stumble upon that. You should open a new question about that specific problem which i'm happy to link to prominently. – Georg Fritzsche May 27 '10 at 09:55
  • Georg, see http://stackoverflow.com/questions/2925279/iwebbrowser2-how-to-force-links-to-open-in-new-window – Rob McAfee May 27 '10 at 21:55
2

Have a look at the following article:

WebBrowser Customization

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • The MSDN article is a good resource, but it doesn't answer this question. MSDN explains how to *prevent* new windows, but not how to force new windows to be opened. The docs imply you could do this by hooking the DISPID_BEFORENAVIGATE2 event, but that event doesn't have enough context to differentiate the user clicking a link from script-based activity. For example, if you load amazon.com, the initial page load will trigger a bunch of other requests that result in BeforeNavigate events of their own. – Rob McAfee May 25 '10 at 21:29