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

  • Home
  • SEARCH
  • 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 8910775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:46:28+00:00 2026-06-15T03:46:28+00:00

I’ve been asked to retro-fit a custom web-browser built around the IE 9 control.

  • 0

I’ve been asked to retro-fit a custom web-browser built around the IE 9 control. One of the requirements was that all pop-up windows must be caught and redirected into a new tab. The customer didn’t want any floating stand-alone windows to appear.

The previous developer implemented the following function to capture these cases and open a new tab instead.

public void NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
{
    BrowserExtendedNavigatingEventArgs args = new BrowserExtendedNavigatingEventArgs(ppDisp, new Uri(bstrUrl), null, (UrlContext)dwFlags);
    _Browser.OnStartNewWindow(args);
    Cancel = args.Cancel;
    ppDisp = args.AutomationObject;
}

The problem occurs when one of these opened windows expects to be able to call window.close from javascript.

I was hoping I could use this function

public void WindowClosing(bool isChildWindow, ref bool cancel)

to detect the javascript call and close the tab. But this function is never called. The javascript function itself seems to work. The contents of the tab are cleared. How can I detect this scenario and close the tab?

Note that the IE9 active x control is not a hard requirement. But please don’t suggest I switch rendering engines solely for the sake of the purity of the internet :P.

EDIT:

Here is my definition of the DWebBrowserEvents2 interface in C#.

    [ComImport, TypeLibType((short)0x1010), InterfaceType((short)2), Guid("34A715A0-6587-11D0-924A-0020AFC7AC4D")]
    public interface DWebBrowserEvents2
    {
        [DispId(0x111)]
        void NewWindow3(
            [In, Out, MarshalAs(UnmanagedType.IDispatch)] ref object ppDisp, 
            [In, Out] ref bool Cancel,
            [In] uint dwFlags, 
            [In, MarshalAs(UnmanagedType.BStr)] string bstrUrlContext, 
            [In, MarshalAs(UnmanagedType.BStr)] string bstrUrl);

        [DispId(253)]
        void OnQuit();

        [DispId(263)]
        void WindowClosing(
            [In] bool isChildWindow,
            [In, Out] ref bool cancel);

        [DispId(283)]
        void WindowStateChanged(
            [In] uint dwFlags,
            [In] uint dwVAlidFlagsMask);

        [DispId(271)]
        void NavigateError(
            [In, MarshalAs(UnmanagedType.IDispatch)] object pDisp,
            [In] ref object URL, [In] ref object frame,
            [In] ref object statusCode, [In, Out] ref bool cancel);
    }
  • 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-06-15T03:46:29+00:00Added an answer on June 15, 2026 at 3:46 am

    Found an answer here: http://social.msdn.microsoft.com/Forums/en/winforms/thread/1cda7799-bf65-4c66-a3bf-488656998191 and it worked for me.

    In case that link goes away, here’s the answer from that page:

    // A delegate type for hooking up close notifications.
    public delegate void ClosingEventHandler(object sender, EventArgs e);
    
    // We need to extend the basic Web Browser because when a web page calls
    // "window.close()" the containing window isn't closed.
    public class ExtendedWebBrowser : WebBrowser
    {
      // Define constants from winuser.h
      private const int WM_PARENTNOTIFY = 0x210;
      private const int WM_DESTROY = 2;
    
      public event ClosingEventHandler Closing;
    
      protected override void WndProc(ref Message m)
      {
        switch (m.Msg)
        {
          case WM_PARENTNOTIFY:
            if (!DesignMode)
            {
              if (m.WParam.ToInt32() == WM_DESTROY)
              {
                Closing(this, EventArgs.Empty);
              }
            }
            DefWndProc(ref m);
            break;
          default:
            base.WndProc(ref m);
            break;
        }
      }
    }
    
    //Then your containing class has the following:
    private ExtendedWebBrowser browserControl;
    this.browserControl.Closing +=new ClosingEventHandler(browserControl_Closing);
    private void browserControl_Closing(object sender, EventArgs e)
    {
      this.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.