none
Get Popup URL in NewWindow2 Event RRS feed

  • Question

  • Hi!

    I have a web browser in my windows forms app. When a popup is about to open, I use this code to open the popup url in the parent web browser:

            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                nativeBrowser = (SHDocVw.WebBrowser)wb.ActiveXInstance;
                nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
                nativeBrowser.NewWindow3 += nativeBrowser_NewWindow3;
            }

            private void nativeBrowser_NewWindow2(ref object ppDisp, ref bool Cancel)
            {
                ppDisp = wb.ActiveXInstance;
            }

            private void nativeBrowser_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
            {
                wb.Navigate(bstrUrl);
            }

    I'm using Microsoft Internet Controls COM reference (1.1). In some cases the NewWindow3 event is fired and in others cases the NewWindow2 event. The code in the NewWindow3 event works well, however the code in the NewWindow2 event doesn't work. I don´t know how to get the url in this event. How could I get it?

    Thanks in advance.


    • Edited by betozg31 Monday, June 17, 2019 3:15 PM
    Monday, June 17, 2019 3:14 PM

Answers

All replies

  • Hi,

    "NewWindow2" does not contain the parameter "url". And "NewWindow3" is an extension to "NewWindow2" with the parameter "bstrUrl" added. For details, you can refer to the following two documents.

    NewWindow2 Event;

    NewWindow3 Event.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 18, 2019 9:40 AM
  • I see, but I have 2 questions:

    1. My application is installed in my clients computers. Why is the NewWindow2 event fired in some computers while the NewWindow3 event is fired in other computers?

    2. How could I make the NewWindow3 event fire in any computer? (Maybe depends on the IE settings).

    Thanks.

    • Edited by betozg31 Tuesday, June 18, 2019 10:52 AM
    Tuesday, June 18, 2019 10:50 AM
  • If the machine only support NewWindow2 (e.g. Windows XP pre SP2) you can get the URL in the BeforeNavigate2 event of the object you passed to ppDisp in NewWindow2

    If you use embedded interop types (a feature new in .Net 4) NewWindow3 won't fire but NewWindow2 would.  

    Anyway if you are navigating away during NewWindow3 and not setting ppDisp shouldn't you set Cancel to true? 



    Visual C++ MVP



    Wednesday, June 19, 2019 10:26 PM
  • Yes, I set Cancel to true but I forgot to add that code line in the question (there's more code but I put what is necessary). I'll use the BeforeNavigate2 event to get the url. Thank you Sheng
    Friday, June 21, 2019 11:12 AM