• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            <2008年10月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            統(tǒng)計(jì)

            • 隨筆 - 44
            • 文章 - 0
            • 評論 - 86
            • 引用 - 0

            常用鏈接

            留言簿(6)

            隨筆分類(31)

            隨筆檔案(44)

            Mining

            最新隨筆

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            獲取IE (控件)的所有鏈接(包括Frameset, iframe)

            IE 頂層 body 節(jié)點(diǎn)通過IHTMLElement->get_all 方法無法獲取iframe 里面的節(jié)點(diǎn)列表

            CComPtr<IHTMLElement> body;
             
            CComPtr
            <IDispatch> spDispCollection;
            body
            ->get_all(&spDispCollection);

            所以要獲取iframe/frame(frameset) 里面的節(jié)點(diǎn)列表的話, 則需要根據(jù)body/doc 找到frames, 然后從frames -> IHTMLWindow2 -> IHTMLDocument2 . 主要有2個方法, 下面是代碼片段
            方法一:
            IHTMLDocument2 *pDoc = 瀏覽器的Document(IWebBrowser2->IDispatch->IHTMLDocument2); 
            IHTMLWindow2 
            *pHTMLWnd = NULL; 
            IHTMLDocument2 
            *pFrameDoc=NULL; 
            IHTMLFramesCollection2 
            *pFramesCollection=NULL; 
            LPDISPATCH lpDispatch; 

            long p; 
            VARIANT varindex,varresult; 
            varresult.vt
            =VT_DISPATCH; 
            varindex.vt 
            = VT_I4; 
            if(pDoc!=NULL) 

                HRESULT hr
            =pDoc->get_frames(&pFramesCollection); 
                
            if(SUCCEEDED(hr)&&pFramesCollection!=NULL) 
                { 
                    hr
            =pFramesCollection->get_length(&p); 
                    
            if(SUCCEEDED(hr)) 
                        
            for(int i=0; i<p; i++
                        { 
                            varindex.lVal 
            = i; 
                            
            if(pFramesCollection->item(&varindex, &varresult) ==S_OK) 
                            { 
                                lpDispatch
            =(LPDISPATCH)varresult.ppdispVal; 
                                
            if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd))) 
                                { 
                                    
            if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc))) 
                                    { 
                                        
            //work with the pFrameDoc 
                                    } 
                                    pHTMLWnd
            ->Release(); 
                                    pHTMLWnd
            =NULL; 
                                } 
                            } 
                        } 
                        pFramesCollection
            ->Release(); 
                } 
                pDoc
            ->Release(); 
            }

            方法二:
            CComQIPtr<IHTMLElement> pElem = ; // 可以遞歸上面的 CComPtr<IDispatch> spDispCollection 來得到
            CComBSTR bstrTagName;
            pElem
            ->get_tagName(&bstrTagName);
            if ( lstrcmpiW(L"IFRAME", bstrTagName)==0 ||
                    lstrcmpiW(L
            "FRAME", bstrTagName)==0 )
            {
                CComQIPtr
            <IHTMLFrameBase2>    _framebase2;
                CComPtr
            <IHTMLWindow2>        _framewindow;
                CComPtr
            <IHTMLDocument2>        _framedoc;
                
                
            if( (_framebase2 = spItem) 
                    
            && SUCCEEDED( _framebase2->get_contentWindow(&_framewindow) ) && _framewindow!=NULL 
                    
            && SUCCEEDED( _framewindow->get_document(&_framedoc) ) && _framedoc!=NULL )
                {
                    
            // 對 _framedoc 節(jié)點(diǎn)進(jìn)行處理
                }
            }


            iframe 跨域訪問(cross frame)  zz from : http://codecentrix.blogspot.com/2007/10/when-ihtmlwindow2getdocument-returns.html 
            由于安全性限制, 為防止跨域腳本攻擊, 當(dāng)frames 跨域的時候, IHTMLWindow2::get_document 調(diào)用將返回 E_ACCESSDENIED .
            下面函數(shù) HtmlWindowToHtmlDocument  對于跨域的frame 通過 IHTMLWindow2 -> IID_IWebBrowserApp -> IHTMLWindow2 繞過了限制.

            // Converts a IHTMLWindow2 object to a IHTMLDocument2. Returns NULL in case of failure.
            // It takes into account accessing the DOM across frames loaded from different domains.
            CComQIPtr<IHTMLDocument2> HtmlWindowToHtmlDocument(CComQIPtr<IHTMLWindow2> spWindow)
            {
                 ATLASSERT(spWindow 
            != NULL);

                 CComQIPtr
            <IHTMLDocument2> spDocument;
                 HRESULT hRes 
            = spWindow->get_document(&spDocument);
                
                 
            if ((S_OK == hRes) && (spDocument != NULL))
                 {
                      
            // The html document was properly retrieved.
                      return spDocument;
                 }

                 
            // hRes could be E_ACCESSDENIED that means a security restriction that
                 
            // prevents scripting across frames that loads documents from different internet domains.
                 CComQIPtr<IWebBrowser2>  spBrws = HtmlWindowToHtmlWebBrowser(spWindow);
                 
            if (spBrws == NULL)
                 {
                      
            return CComQIPtr<IHTMLDocument2>();
                 }

                 
            // Get the document object from the IWebBrowser2 object.
                 CComQIPtr<IDispatch> spDisp;
                 hRes 
            = spBrws->get_Document(&spDisp);
                 spDocument 
            = spDisp;

                 
            return spDocument;
            }


            // Converts a IHTMLWindow2 object to a IWebBrowser2. Returns NULL in case of failure.
            CComQIPtr<IWebBrowser2> HtmlWindowToHtmlWebBrowser(CComQIPtr<IHTMLWindow2> spWindow)
            {
                 ATLASSERT(spWindow 
            != NULL);

                 CComQIPtr
            <IServiceProvider>  spServiceProvider = spWindow;
                 
            if (spServiceProvider == NULL)
                 {
                      
            return CComQIPtr<IWebBrowser2>();
                 }

                 CComQIPtr
            <IWebBrowser2> spWebBrws;
                 HRESULT hRes 
            = spServiceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&spWebBrws);
                 
            if (hRes != S_OK)
                 {
                      
            return CComQIPtr<IWebBrowser2>();
                 }

                 
            return spWebBrws;
            }


            附:
            IE(控件/接口)中主要有4個部分, Browser, Document, Frame/IFrame, Element , 其對應(yīng)接口分別是
            Browser         -    IWebBrowser2
            Document      -    IHTMLDocument2
            Frame/IFrame-    IHTMLWindow2
            Element         -    IHTMLElement
            可以通過下面方法互相獲取
            browser      -> document        IWebBrowser2::get_Document
            document     -> frame           IHTMLDocument2::get_parentWindow
            frame        -> document        IHTMLWindow2::get_document
            frame        -> parent frame    IHTMLWindow2::get_parent
            frame        -> children frames IHTMLWindow2::get_frames
            element     -> Frame             IHTMLElement->QI(IHTMLFrameBase2) -> IHTMLFrameBase2->get_contentWindow -> IHTMLWindow2

            ref:
            在多Frame的網(wǎng)頁中怎么取出各個Frame的IHTMLDocument2的接口!急用.(高分)
            在文章 When IHTMLWindow2::get_document returns E_ACCESSDENIED 解決了iframe 跨域訪問的問題

            posted on 2008-07-30 19:17 泡泡牛 閱讀(7214) 評論(3)  編輯 收藏 引用 所屬分類: Develop

            評論

            # re: 獲取IE (控件)的所有鏈接(包括Frameset, iframe)  2008-08-01 19:00 小笨象

            樓主是否試過如果跨域的話,也能取到不?
            希望樓主能測試一下,然后告訴大家。
            謝謝。
              回復(fù)  更多評論    

            # re: 獲取IE (控件)的所有鏈接(包括Frameset, iframe)  2008-08-02 00:32 泡泡牛

            @小笨象

            http://codecentrix.blogspot.com/2007/10/when-ihtmlwindow2getdocument-returns.html

            這里已經(jīng)解決了這個問題, 嘿嘿, 順便抄到了這里:)
              回復(fù)  更多評論    

            # re: 獲取IE (控件)的所有鏈接(包括Frameset, iframe)  2008-08-14 21:22 小笨象

            樓主。謝謝啊。
            我繼續(xù)學(xué)習(xí)。
              回復(fù)  更多評論    
            久久久久久久久无码精品亚洲日韩 | 亚洲国产高清精品线久久| 91久久精一区二区三区大全| 欧美亚洲国产精品久久高清| 久久国产精品无码网站| 国产L精品国产亚洲区久久 | 国产精品美女久久久免费| 2021精品国产综合久久| 国产欧美久久久精品| 国产麻豆精品久久一二三| 国产精品无码久久久久久| 99久久无色码中文字幕| 久久综合综合久久97色| 久久亚洲欧美日本精品| 久久亚洲精品中文字幕三区| 国产精品gz久久久| 欧美午夜精品久久久久久浪潮| 久久男人中文字幕资源站| 亚洲国产成人久久综合野外| 久久国语露脸国产精品电影| 久久精品中文字幕无码绿巨人| 久久99精品国产| 久久综合五月丁香久久激情| 一级做a爰片久久毛片毛片| 精品多毛少妇人妻AV免费久久| 狠狠色丁香久久婷婷综合| 精品久久一区二区三区| 久久久久亚洲?V成人无码| 97精品依人久久久大香线蕉97 | 久久无码一区二区三区少妇| 国内精品综合久久久40p| 日韩一区二区久久久久久 | 日产精品久久久一区二区| 精品永久久福利一区二区| 开心久久婷婷综合中文字幕| 久久久av波多野一区二区| 亚洲国产精品一区二区三区久久| 人妻无码久久一区二区三区免费| 国产亚洲成人久久| 狠狠色丁香久久婷婷综合五月| 91久久香蕉国产熟女线看|