乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

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

       imzjw 2010-04-10
      獲取IE (控件)的所有鏈接(包括Frameset, iframe)zz
      2008-08-15 13:38

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

      CComPtr<IHTMLElement> body;

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

      所以要獲取iframe/frame(frameset) 里面的節(jié)點列表的話, 則需要根據(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é)點進(jìn)行處理
           }
      }


      iframe 跨域訪問(cross frame)   zz from : http://codecentrix./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

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多