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
2009-09-22 14:35:40
How to register for IWebBrowser2 events? I have only IWebBrowser2 object.
dominolog
2009-09-22 15:59:10
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
2009-09-23 02:11:16
Ok. Thanks, I've found it althought in WTL it is not as easy as in MFC.
dominolog
2009-09-30 10:22:59
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
2010-05-25 23:15:09
@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
2010-05-26 05:43:31
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
2010-05-26 22:14:40
@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
2010-05-27 09:55:50
Georg, see http://stackoverflow.com/questions/2925279/iwebbrowser2-how-to-force-links-to-open-in-new-window
Rob McAfee
2010-05-27 21:55:58
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
2010-05-25 21:29:35