WebBrowser control: stuck with interframe security
-
Hello, I'm trying to parse frames from pages using the WebBrowser control and sometimes when frames or iframes are not from the same domain as the main page, I get an interframe security problem. This problem (or feature of IE) is well known and a workaround exists for C++. My problem is that I'm not comfortable with COM object and don't known how to translate the workaround into C#. Any help on translating this will be greatly welcome. Here is the KB article from MSDN: KB196340 - HOWTO: Get the WebBrowser Object Model of an HTML Frame
// Get the IDispatch of the document LPDISPATCH 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++) { // QI for IWebBrowser here to see if we have an embedded browser IWebBrowser2* pBrowser; hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser); pUnk->Release(); if (SUCCEEDED(hr)) { // Refresh the frame pBrowser->Refresh(); pBrowser->Release(); } } pEnumerator->Release(); }
Thanks, R. LOPES Just programmer.