webbrowser控件的IHTMLDocument3 or2接口的iframe问题(非安全设置) ( 积分: 300 )

  • 主题发起人 carolson2
  • 开始时间
C

carolson2

Unregistered / Unconfirmed
GUEST, unregistred user!
webbrowser控件的IHTMLDocument3 or2接口的iframe问题(非安全设置)


已知 不同domain下的iframe IE设置有安全限制。 (但本地程序下怎么也能获得接口吧?!!!)
比如 www.abc.com/1.html 下iframe了 www.bbb.com/2.htm
需要通过1.html 去获得被iframe 的2.html的links 等等。delphi 下无人实现,但是c++下有人实现了。 如下两段代码似乎是网上唯一可以得到的c++代码去获得iframe中的接口。

哪位高人能将其翻译为delphi的? 实现:
1. webbrowser先访问 www.abc.com/1.htm ( 1.htm中iframe 了 www.bbb.com/2.htm)
2. IHTMLDocument3 or 2 接口到webbrowser (很容易实现)
3. 获得1.htm 中的 iframe collection
4. 最终获得指定iframe的接口,实现获得iframe的内容以及各类元素的操作。


C++代码如下:
***********代码1*************

CComPtr pDoc3;
hr = pDoc2->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3) ;
if(hr==S_OK)
{
CComBSTR bstrName("FRAME");
CComPtr pElemCollFrame;
hr=pDoc3->getElementsByTagName(bstrName,&pElemCollFrame);
if (hr==S_OK)
{
long pLength;
hr=pElemCollFrame->get_length(&pLength);
if(hr==S_OK)
{
for(int i=0;iitem(vIndex,vIndex,&pDispFrame);
if(hr==S_OK)
{
CComPtr pElemFrame;
hr=pDispFrame->QueryInterface(IID_IHTMLElement,(void**)&pElemFrame);
if(hr==S_OK)
{
CComPtr pFrameBase2;
hr=pElemFrame->QueryInterface(IID_IHTMLFrameBase2,(void**)&pFrameBase2);
if(hr==S_OK)
{
CComPtr pWindow2;
hr=pFrameBase2->get_contentWindow(&pWindow2);
if(hr==S_OK)
{
CComPtr pDoc2Frame;
hr=pWindow2->get_document(&pDoc2Frame);
if (hr==S_OK)
{
//得到IHTMLDocument2
}
}
}
}
}
pDispFrame->Release();
}
}
}
}


***********实现方法之2************
void EnumFrame( IHTMLDocument2 * pIHTMLDocument2 )
{
if ( !pIHTMLDocument2 )return;

HRESULT hr;

CComPtr< IHTMLFramesCollection2 > spFramesCollection2;
pIHTMLDocument2->get_frames( &amp;spFramesCollection2 );//取得框架frame的集合

long nFrameCount=0;//取得子框架个数
hr = spFramesCollection2->get_length( &amp;nFrameCount );
if ( FAILED ( hr ) || 0 == nFrameCount )return;

for(long i=0; iitem( &amp;CComVariant(i), &amp;vDispWin2 );
if ( FAILED ( hr ) )continue;

CComQIPtr< IHTMLWindow2 > spWin2 = vDispWin2.pdispVal;
if( !spWin2 )continue;//取得子框架的 IHTMLWindow2 接口

CComPtr < IHTMLDocument2 > spDoc2;
spWin2->get_document( &amp;spDoc2 );//取得字框架的 IHTMLDocument2 接口
}



期盼翻译解决:)
 
顶部