You are currently offline, waiting for your Internet to reconnect

How to get the WebBrowser object model of an HTML frame

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
This article details the standard technique WebBrowser control hosts canuse to access the WebBrowser object model of frame windows in an HTML pageinside the control. This object model provides extra functionality that isnot exposed for the frame window through the HTML object model.
More information
The following code demonstrates how to access the WebBrowser Object Modelof frames in an HTML page to refresh the contents of each frame.

The most important piece of the code uses the IOleContainer::EnumObjectsmethod of the HTML Document object to enumerate embeddings on the page.Each of these embeddings represents a control on the page. By querying eachcontrol object for IWebBrowser2, this code can determine whether thecontrol is a sub-frame. And IWebBrowser2 represents the WebBrowser ObjectModel; if QueryInterface succeeds for this interface, the result is areference to the WebBrowser Object Model.
// Get the IDispatch of the documentLPDISPATCH lpDisp = NULL;lpDisp = m_webBrowser.GetDocument();if (lpDisp){   IOleContainer* pContainer;   // Get the container   HRESULT hr = lpDisp->QueryInterface(IID_IOleContainer,                                       (void**)&pContainer);   lpDisp->Release();   if (FAILED(hr))      return hr;   IEnumUnknown* pEnumerator;   // Get an enumerator for the frames   hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);   pContainer->Release();   if (FAILED(hr))      return hr;   IUnknown* pUnk;   ULONG uFetched;   // Enumerate and refresh all the frames   for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnk, &uFetched); i++)   {      IWebBrowser2* pBrowser;      hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);      pUnk->Release();      if (SUCCEEDED(hr))      {         // Refresh the frame         pBrowser->Refresh();         pBrowser->Release();      }   }   pEnumerator->Release();}
Note ActiveX controls hosted in an HTML page can use this technique in asimilar manner. In general, an ActiveX control that accesses the unsafeWebBrowser Object Model is not safe for scripting and should implementIObjectSafety interface accordingly for security.
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by ScottRoberts, Microsoft Corporation.
WebBrowser Frame

Article ID: 196340 - Last Review: 06/22/2014 19:27:00 - Revision: 5.0

  • kbFAQ kbhowto kbwebbrowser KB196340
type='text/javascript' src='" + (window.location.protocol) + "//'><\/script>");