ie编程 同样的代码解析同样的页面时,有的机器会报拒绝访问?该如何处理
ie编程 同样的代码解析同样的页面时,有的机器会报拒绝访问?
ie编程 同样的代码解析同样的页面时,有的机器会报拒绝访问?有的机器完全正常。
目标页面是一个B/S系统,访问地址相同。操作系统相同(xp sp2)
为什么呢?那位大侠能帮小弟解惑,不胜感激啊~~~~~~
代码如下:其中pIHTMLDocument2 由ie窗体的hwnd获得,跟这个有关系吗?
void EnumFrame( IHTMLDocument2 * pIHTMLDocument2 )
{
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 接口
}
}
------解决方案--------------------
这种情况也遇到过,后证实为IE安全设置
------解决方案--------------------
看安全区域选项中是否允许跨框架脚本
------解决方案--------------------
框架文档的域名和主页的不一样,安全起见,是不允许访问的。不过可以通过IserviceProvider绕过去。
你已经得到 IHTMLWindow2 的指针 pW 了,那么
ie编程 同样的代码解析同样的页面时,有的机器会报拒绝访问?有的机器完全正常。
目标页面是一个B/S系统,访问地址相同。操作系统相同(xp sp2)
为什么呢?那位大侠能帮小弟解惑,不胜感激啊~~~~~~
代码如下:其中pIHTMLDocument2 由ie窗体的hwnd获得,跟这个有关系吗?
void EnumFrame( IHTMLDocument2 * pIHTMLDocument2 )
{
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 接口
}
}
------解决方案--------------------
这种情况也遇到过,后证实为IE安全设置
------解决方案--------------------
看安全区域选项中是否允许跨框架脚本
------解决方案--------------------
框架文档的域名和主页的不一样,安全起见,是不允许访问的。不过可以通过IserviceProvider绕过去。
你已经得到 IHTMLWindow2 的指针 pW 了,那么
- C/C++ code
IWebBrowser2 * pWB = NULL; if(pW != NULL) { IServiceProvider * pProvider = NULL; pW->QueryInterface(IID_IServiceProvider,(void **)&pProvider); if(pProvider != NULL) { pProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pWB); pProvider->Release(); } }