问题是这样的:例如 <body>
  <iframe width="762" scrolling="no" height="60" frameborder="no" allowtransparency="true"  marginheight="0"    marginwidth="0" border="0" src="ifream.html" id="lsiframe2"></iframe>
  <button value="取得" onclick="getIf();">取得</button>
 </body>在body中插入iframe 
然后再iframe中有一个元素的id是 good 当想获取这个元素的时候 js会这样处理: ifr= document.getElementById('lsiframe2');
var gDiv= ifr.contentWindow.document.getElementById('good');但是在VC中 我用getElementById 拿到那个iframe 后 怎么再拿'good' 呢? 请给出代码! 谢谢!

解决方案 »

  1.   

    1) 先根据 iframe的id得到iframe对应的IHTMLDocument2
    参看:http://www.codeguru.com/cpp/i-n/internet/browsercontrol/article.php/c130652) iframe对应的IHTMLDocument2, QueryInterface得到 IHTMLDocument3
        然后调用 IHTMLDocument3 getElementById() 得到 good元素对应的 IHTMLElement
      

  2.   

            CComPtr<IUnknown> pDocument = m_pIEOperate->GetDocument();
    CComPtr<IHTMLDocument2> pTop;
    pDocument->QueryInterface(IID_IHTMLDocument2, (void**)&pTop);
    IHTMLDocument2* pframeDocument;
    if (pTop)
    {
    getFrameDocumentById(pTop, DICT_UPDATE_ID, &pframeDocument);
    }
    CComPtr<IHTMLDocument3> pFrame;
    pframeDocument->QueryInterface(IID_IHTMLDocument3, (void**)&pFrame);
    pframeDocument->Release();
    CComPtr<IHTMLElement> elem;
    if (pFrame)
    {
    pFrame->getElementById(CComBSTR(L"xixiking"), &elem);
    }
    if (elem)
    {
    CString str = CString(L"很好");
    elem->setAttribute(bstr_t(L"name"), variant_t(str));
    }*/elem 还是拿不到啊
      

  3.   

    执行到那步出错了? 
    pFrame 得到了没有?
    还是说,pFrame->getElementById(CComBSTR(L"xixiking"), &elem); 
    这一步执行后elem为空?
      

  4.   

    pFrame->getElementById(CComBSTR(L"xixiking"), &elem); 
    这一步执行后elem为空
      

  5.   

    你frame页面中是否有<xxx id="xixiking">元素?
    你把你frame页面的html代码贴出来
      

  6.   

    CComPtr<IDispatch> pDisp = (IDispatch*)GetDocument();
    CComPtr<IHTMLDocument3> pDoc;
    HRESULT hr = pDisp->QueryInterface(IID_IHTMLDocument3, (void**)&pDoc);
    if (SUCCEEDED(hr))
    {
    hr = pDoc->getElementById(CComBSTR(szId), pElem);
    return (bool)(SUCCEEDED(hr));
    }
    }上面的这段代码必现在页面的Loading结束之后才能获取到Element的。
      

  7.   

    楼上对的太对了 呵呵 十分感谢skyxie 我的问题已经解决了 就是楼上laiyiling说的问题
    感谢两位大虾!