Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:04:50+00:00 2026-05-23T10:04:50+00:00

I am trying to implement a simple web browser control in one of my

  • 0

I am trying to implement a simple web browser control in one of my apps. This is to help integrate a web app into a toolset i am creating.

The problem is, this web app absolutly loves popup windows….

When a popup is opened, it opens in an IE window which is not a child of the MDI Container form that my main window is part of.

How can i get any and all popups created by clicking links in my WebBrowser to be a child of my MDI container (similar to setting the MDIParent property of a form)?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:04:51+00:00Added an answer on May 23, 2026 at 10:04 am

    The web browser control supports the NewWindow event to get notified about a popup window. The Winforms wrapper however does not let you do much with it, you can only cancel the popup. The native COM wrapper permits passing back a new instance of the web browser, that instance will then be used to display the popup.

    Taking advantage of this requires some work. For starters, use Project + Add Reference, Browse tab and select c:\windows\system32\shdocvw.dll. That adds a reference to the native COM interface.

    Create a form that acts as the popup form. Drop a WebBrowser on it and make its code look similar to this:

    public partial class Form2 : Form {
        public Form2() {
            InitializeComponent();
        }
        public WebBrowser Browser {
            get { return webBrowser1; }
        }
    }
    

    The Browser property gives access to the browser that will be used to display the web page in the popup window.

    Now back to the main form. Drop a WebBrowser on it and make its code look like this:

    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            webBrowser1.Url = new Uri("http://google.com");
        }
        SHDocVw.WebBrowser nativeBrowser;
        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);
            nativeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
        }
        protected override void OnFormClosing(FormClosingEventArgs e) {
            nativeBrowser.NewWindow2 -= nativeBrowser_NewWindow2;
            base.OnFormClosing(e);
        }
    
        void nativeBrowser_NewWindow2(ref object ppDisp, ref bool Cancel) {
            var popup = new Form2();
            popup.Show(this);
            ppDisp = popup.Browser.ActiveXInstance;
        }
    }
    

    The OnLoad method obtains a reference to the native COM interface, then subscribes an event handler to the NewWindow2 event. I made sure to unsubscribe that event in the FormClosing event handler, not 100% sure if that’s necessary. Better safe then sorry.

    The NewWindow2 event handler is the crux, note that the first argument allows passing back an untyped reference. That should be the native browser in the popup window. So I create an instance of Form2 and Show() it. Note the argument to Show(), that ensures that the popup is an owned window. Substitute this as necessary for your app, I assume you’d want to create an MDI child window in your case.

    Do beware that this event doesn’t fire for the window displayed when Javascript uses alert(). The browser doesn’t treat that window as an HTML popup and doesn’t use a browser window to display it so you cannot intercept or replace it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use copy'n paste in one of my web apps and have
i am creating a web project using JSP, and is trying to implement a
I'm trying to make a simple username/password authentication in a Spring Security web app.
I'm trying to implement a simple form-based login for my web application deployed with
I'm trying to implement a simple web server on Linux that connects to the
This maybe a very noobish question but I am trying to implement a simple
Background I'm trying to implement a simple web server part as a web interface
What I'm trying to do is this: I've got a web app the user
I'm trying to implement a simple web application that will sit between IIS and
I'm trying to implement a simple horizontal navigation menu that just shows a single

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.