views:

438

answers:

2

Hello 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  A: 

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.

Georg Fritzsche
How to register for IWebBrowser2 events? I have only IWebBrowser2 object.
dominolog
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
Ok. Thanks, I've found it althought in WTL it is not as easy as in MFC.
dominolog
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
@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
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
@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
Georg, see http://stackoverflow.com/questions/2925279/iwebbrowser2-how-to-force-links-to-open-in-new-window
Rob McAfee
+2  A: 

Have a look at the following article:

WebBrowser Customization

Remy Lebeau - TeamB
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