locked
opening new tab in IE7 via IHTMLWindow2::open method. Possible? RRS feed

  • Question

  • hi
    i need to open new tab in IE7 from my extension code and to get an IHTMLWindow2*, pointing to this tab.
    Exactly tab, not a new window. Is it possible to do it via IHTMLWindow2::open method or are where any other ways to do it from extension?
    I walked through some docs and forums and heard opinions that a place(new window or tab) in which IE7 opens pop-ups (as ones created by IHTMLWindow2::open) is controlled by user settings and extension can't change it?
    Can't anyone tell is it so?
    So sad if it is....

    Than you in advance.
    Friday, November 10, 2006 3:52 PM

Answers

  • You could use IWebBrowser2::Navigate2 with navOpenInNewTab flag. But note you wont get the IWebBrowser2 (so eventually the IHTMLWindow2) of the new tab. Since its a new tab, your extension would anyways be loaded for the new tab and you can get the IWebBrowser2 during the IObjectWithSite::SetSite call.
    Friday, November 10, 2006 6:23 PM
  • Alexander, the "if necessary" part simply refers to the edge case where the new tab was redirected to another IE process due to Protected Mode. In that case we bring the other IE window to the foreground, whereas we bring neither the tab nor the new window to the foreground in the navOpenInBackgroundTab case.

    To answer the second question, no unfortunately there's no programmatic way for an extension to select a tab in IE7. IE does not yet expose a full-fledged tabbed browsing API set. When you open a single tab using navOpenInNewTab, that tab will be selected by default.

    We also don't expose an API to check whether tabs are enabled, but navOpenInNewTab will fail if tabbed browsing is disabled so that your extension can fall back on opening a new window. See the Remarks section on http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/navigate2.asp for some more information on navOpenInNewTab.

    - Tony Schreiner

    Tuesday, November 14, 2006 7:33 PM

All replies

  • You could use IWebBrowser2::Navigate2 with navOpenInNewTab flag. But note you wont get the IWebBrowser2 (so eventually the IHTMLWindow2) of the new tab. Since its a new tab, your extension would anyways be loaded for the new tab and you can get the IWebBrowser2 during the IObjectWithSite::SetSite call.
    Friday, November 10, 2006 6:23 PM
  • Thank you for your answer
    Yes, another copy of my extension loads in new tab, it's ok, but i need to manage new tab from the code where i create it. Exactly i need to perform this steps:

    1) take html from the current tab
    2) make some transforms with this html
    3) open a new tab
    4) load transformed html to this new tab

    so i see two ways: to have pointer to new tab IWebBrowser2(IHTMLWindow2) in the place where it is creating or notify extension in the new tab in some manner.

    The first suits me much better cause i wouldn't have to rewrite a lot of code from extension for IE6.
    Couldn't you advise something to solve my problem?

    Thank You

    Monday, November 13, 2006 9:13 AM
  • also want to ask whether i can detect is IE running in protected mode or not in my extension code?
    Monday, November 13, 2006 9:33 PM
  •  Sharath Udupa - MSFT wrote:
    You could use IWebBrowser2::Navigate2 with navOpenInNewTab flag. But note you wont get the IWebBrowser2 (so eventually the IHTMLWindow2) of the new tab. Since its a new tab, your extension would anyways be loaded for the new tab and you can get the IWebBrowser2 during the IObjectWithSite::SetSite call.


    and what about activating new tab when creating it with IWebBrowser2::Navigate2 method.
    MSDN says:
    navOpenInNewTab

    Windows Internet Explorer 7 or later. Open the resource or file in a new tab. Allow the destination window to come to the foreground, if necessary.

    nessesary to who? :)
    are there any other ways to activate tab?
    and another question is: how can i check whether tabs are enabled in IE7?

    Thank you
    Tuesday, November 14, 2006 3:23 PM
  • Alexander, the "if necessary" part simply refers to the edge case where the new tab was redirected to another IE process due to Protected Mode. In that case we bring the other IE window to the foreground, whereas we bring neither the tab nor the new window to the foreground in the navOpenInBackgroundTab case.

    To answer the second question, no unfortunately there's no programmatic way for an extension to select a tab in IE7. IE does not yet expose a full-fledged tabbed browsing API set. When you open a single tab using navOpenInNewTab, that tab will be selected by default.

    We also don't expose an API to check whether tabs are enabled, but navOpenInNewTab will fail if tabbed browsing is disabled so that your extension can fall back on opening a new window. See the Remarks section on http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/navigate2.asp for some more information on navOpenInNewTab.

    - Tony Schreiner

    Tuesday, November 14, 2006 7:33 PM
  • Thank you, Tony
    You answer is exactly what i wanted to learn, thanks a lot.

    Alexander Petukhov
    Tuesday, November 14, 2006 8:21 PM
  • sorry for offtopic, what is the best way to determine IE version?


    Wednesday, November 15, 2006 9:14 AM
  • This article lists out some options which you could use http://support.microsoft.com/default.aspx/kb/164539
    Thursday, November 16, 2006 9:13 AM
  • Thank you. I have read it, but prefered to ask for some new interfaces to recognize IE version. If S_OK==QueryInterface this is IE7 :)

    back to the tabs, i'd like to offer some general designs for working with tabs, i was obliged to use, as i see many people having the same problems:

    1)Enumerating tabs
    If you have HWND of browser window you can simply find all its childs of TabWindowClass class.

    IWebBrowser2* pWBrowser;
    //....getting IWebBrowser2 for currect tab in some manner
    HWND hWndBrowser;
    pWBrowser->get_HWND((long*)&hWndBrowser);
    EnumChildWindows(hWndBrowser, EnumChildProc, NULL);

    where:

    BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
    {
        TCHAR szClassName[1000];
        GetClassName(hwnd, szClassName, 1000);
        if (!_tcscmp(szClassName, _T("TabWindowClass")))
        {
            //you have found a tab
        }
    }

    2) getting tab's IWebBrowser2 interfaces from the extension related to another tab. (this interface can help you to interact with a tab from another)
    I created a global map<HWND, IStream*> in my extension. It's aim is to keep pairs "Tab's HWND"-"IWebBrowser2 interface of this tab".
    When in SetSite method of object implementing IObjectWithSite interface you can get tab HWND and IWebBrowser2 for current tab in the following manner:

    map<HWND, IStream*> MapHWND;

    STDMETHODIMP CSomeObjectWithSite::SetSite(IUnknown* pUnkSite)
    {
        //getting IWebBrowser2
        IWebBrowser2* pMainWB;
        IOleCommandTarget* pCmdTarget;
        IServiceProvider* pSP;
        HRESULT hr = pUnkSite->QueryInterface(IID_IOleCommandTarget,     (LPVOID*)&pCmdTarget);
        if (SUCCEEDED(hr))
        {
            hr = pCmdTarget->QueryInterface(IID_IServiceProvider, (LPVOID*)&pSP);

            pCmdTarget->Release();

            if (SUCCEEDED(hr))
            {
                hr = pSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID*)&pMainWB);
            }
            pSP->Release();
        }

        //getting tab's HWND
        hr = pMainWB->QueryInterface( IID_IServiceProvider, (void**)&pSP);
        if( SUCCEEDED(hr) && pSP)
        {
            IOleWindow* pow;
            pSP->QueryService( SID_SShellBrowser, IID_IOleWindow, (void**)&pow );
            if( SUCCEEDED(hr) && pow)
            {
                HWND hWnd = NULL;
                hr = pow->GetWindow( &hWnd );
                if( SUCCEEDED(hr) && hWnd )
                {
                    IStream* pStream;
                    CoMarshalInterThreadInterfaceInStream(IID_IWebBrowser2,
                        pMainWB, &pStream);
                    MapHWND.insert(map<HWND, IStream*>::value_type(hWnd,pStream));
                }
                pow->Release();
            }
            pSP->Release();
        }
    }

    Marshalling interface in stream is needed as tab's are executing on different threads and you might have problems with using interface on a stream different from the one interface was created on.
    To unmarshall interface it's nessesary to use CoGetInterfaceAndReleaseStream.
    So, when you need to do smthng with another tab you can find it in map via it's HWND and to get IWebBrowser2 interface for it.
    When i need to open a new tab and to do something with it, i use IWebBrowser2::Navigate2 method with navOpenInNewTab flag and then wait for the new entry in map.

    3) What tab is active
    I use IsWindowActive function supplying with tab's HWND.

    4) Setting tab active
    I havn't found a way to do it :(



    Thursday, November 16, 2006 9:59 AM
  • "4) Setting tab active
    I havn't found a way to do it :("

    How about if you would set one of the tabbrowser windows visible and hide the current one?

    Wednesday, December 13, 2006 10:23 PM
  • "4) Setting tab active
    I havn't found a way to do it :("

    How about if you would set one of the tabbrowser windows visible and hide the current one?


    Do you find the way to set the tab active?

    Tuesday, February 16, 2010 1:30 AM