How to “Open in New Window” using WebBrowser contr

2019-06-22 08:11发布

问题:

When you use the WebBrowser control in .NET you can "embed" an instance of IE in your application, essentially making your own IE-based Web Browser.

Does anyone know how to make any new windows created (like when the user selects "Open in New Window" from the context menu) open up in another Window of Your Web Browser Application, instead of the computers default browser??

回答1:

Maybe the Source Code from this CodeProject article can help:

Extended .NET 2.0 WebBrowser Control



回答2:

I did this a long time ago in VB.

From what I remember, when a NewWindow2 event was fired by the control, we would cancel the original request and open a separate VB form that contained another instance of the WebBrowser control pointed at the requested URL.

I did a quick google search and it seems like maybe this event isn't as easy to access in .Net. Take a look here for a possible solution.



回答3:

There's a code sample here that contains code for adding the NewWindow2 event to the WebBrowser control. It sure would be nice if they added this event to the WebBrowser control itself.

http://zerosandtheone.com/media/p/277.aspx



回答4:

This site has the best solution I've found if you're using the .net version of the webbrowser control

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/f497f8a5-dac8-48cb-9fce-7936c9389f09