一个网页, 用 <IFrame> 引用了另一个网站的网页,
我想在CHtmlView 中获得 这个 IFrame 的IHTMLWindow2 。
但是试了很多 办法,都会得到拒绝访问的 错误。看到一些不完整 的资料 介绍, ie 处于安全考虑, 禁止 读取 不同域 的网页。
比如:
[ 网页url ] http://aaa.com/aaa.html
[ iframe url ] http://bbb.com/bbb.html
则 不能读取 iframe 中的内容。但是 始终不死心,所以请教 有经验的朋友,看是不是能够得到。
我想在CHtmlView 中获得 这个 IFrame 的IHTMLWindow2 。
但是试了很多 办法,都会得到拒绝访问的 错误。看到一些不完整 的资料 介绍, ie 处于安全考虑, 禁止 读取 不同域 的网页。
比如:
[ 网页url ] http://aaa.com/aaa.html
[ iframe url ] http://bbb.com/bbb.html
则 不能读取 iframe 中的内容。但是 始终不死心,所以请教 有经验的朋友,看是不是能够得到。
解决方案 »
- TCP下bind怎么总是返回-1?
- 璇烽珮鎵嬫寚鐐?>鎬庢牱瑙e喅鎷栧姩绐楀彛闂姩闂
- 如何把openGL后缓冲区内容存储为一个位图文件或JPEG文件
- 请教:基于dialog的工程,如何在窗体大小变化,分辨率变化以及字体大小变化后保持布局?
- 对于一个按钮,如何使其透明呀?就是不遮挡背景位图?
- 请教各位高手怎样用win32 Application编写应用程序?
- LONG (*pfn)(HWND,UINT,WPARAM,LPARAM);请问高手这句是什么意思?
- 写控件时晕了,想了一下午却想不出来。
- 如何判断拨号连接是否在线?
- 关于ado的简单问题?
- 如何判断CHtmlView中的页面完全载入完毕(包含frame)
- 请问高手怎样才能枚举出网页中所有“输入框”位置(包括IFRAME中),在线等
hr = pDoc2->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3) ;
if(hr==S_OK)
{
CComBSTR bstrName("FRAME");
CComPtr<IHTMLElementCollection> 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;i<pLength;i++)
{
IDispatch *pDispFrame=NULL;
CComVariant vIndex=i;
hr=pElemCollFrame->item(vIndex,vIndex,&pDispFrame);
if(hr==S_OK)
{
CComPtr<IHTMLElement> pElemFrame;
hr=pDispFrame->QueryInterface(IID_IHTMLElement,(void**)&pElemFrame);
if(hr==S_OK)
{
CComPtr<IHTMLFrameBase2> pFrameBase2;
hr=pElemFrame->QueryInterface(IID_IHTMLFrameBase2,(void**)&pFrameBase2);
if(hr==S_OK)
{
CComPtr<IHTMLWindow2> pWindow2;
hr=pFrameBase2->get_contentWindow(&pWindow2);
if(hr==S_OK)
{
CComPtr<IHTMLDocument2> pDoc2Frame;
hr=pWindow2->get_document(&pDoc2Frame);
if (hr==S_OK)
{
//得到IHTMLDocument2
}
}
}
}
}
pDispFrame->Release();
}
}
}
}
{
if ( !pIHTMLDocument2 ) return; HRESULT hr; CComPtr< IHTMLFramesCollection2 > spFramesCollection2;
pIHTMLDocument2->get_frames( &spFramesCollection2 ); //取得框架frame的集合 long nFrameCount=0; //取得子框架个数
hr = spFramesCollection2->get_length( &nFrameCount );
if ( FAILED ( hr ) || 0 == nFrameCount ) return; for(long i=0; i<nFrameCount; i++)
{
CComVariant vDispWin2; //取得子框架的自动化接口
hr = spFramesCollection2->item( &CComVariant(i), &vDispWin2 );
if ( FAILED ( hr ) ) continue; CComQIPtr< IHTMLWindow2 > spWin2 = vDispWin2.pdispVal;
if( !spWin2 ) continue; //取得子框架的 IHTMLWindow2 接口 CComPtr < IHTMLDocument2 > spDoc2;
spWin2->get_document( &spDoc2 ); //取得字框架的 IHTMLDocument2 接口
}
}