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

2 Answers 2

2

Have a look at the following article:

WebBrowser Customization

1
  • 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, 2010 at 21:29
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.

8
  • How to register for IWebBrowser2 events? I have only IWebBrowser2 object.
    – cubesoft
    Sep 22, 2009 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. Sep 23, 2009 at 2:11
  • Ok. Thanks, I've found it althought in WTL it is not as easy as in MFC.
    – cubesoft
    Sep 30, 2009 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, 2010 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. May 26, 2010 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.