hr错误是E_ACCESSDENIED,我测试过很多页面,发现有的页面可以的,但是有的页面不行,sina网的主页面有三个iFrame,3个是同样的结果(我通过主IHTMLDocument2接口获得Frames然后再通过每个Frame获取IHTMLWindow2,最后通过IHTMLWindow2的get_Document企图获得IHTMLDocument2)
解决方案 »
- VC 6.0 出现问题了 求 帮助
- 基于对话框,拖出桌面范围就出错。
- 急求助~~~~~MFC 如何在属性表中初始化属性页中的控件?一般在属性表的哪个函数中添加呢?
- 关于ClassView一点的问题?!
- 请问我想自己编写个Edit控件
- 疑惑::GetRecordCount()函数为什么返回的是1?? VC+SQL Server.
- 对于个*.avi或是*.mpg的文件,怎么得知解码后图像格式和声音格式?
- 请前辈们推荐几本SQL语言和SQL SERVER的好书,省得小弟白花银子。谢了!谢了!
- 跨类调用
- ◆→我要在进程间传一个字符串,可通过消息只能传两个参数,我应该怎么办?
- TC中的random函数怎么不能在 vc中用阿
- 分隔窗口
void EnumFrame(CComPtr<IHTMLDocument2>& spDoc,int indent)
{
CComPtr<IHTMLFramesCollection2> spFrameCol;
HRESULT hr;
long count,i;
if(FAILED(spDoc->get_frames(&spFrameCol))) return;
if(FAILED(spFrameCol->get_length(&count))) return;
VARIANT varIndex,varDisp;
VariantInit(&varIndex);
VariantInit(&varDisp);
varIndex.vt=VT_I4;
for(i=0;i<count;i++)
{
CComPtr<IHTMLWindow2> spWin;
CComPtr<IHTMLDocument2> spChildDoc;
varIndex.lVal=i;
if(SUCCEEDED(spFrameCol->item(&varIndex,&varDisp)) && varDisp.vt==VT_DISPATCH)
{
if(SUCCEEDED(hr=varDisp.pdispVal->QueryInterface(IID_IHTMLWindow2,(void**)&spWin)))
{
if(SUCCEEDED(hr=spWin->get_document(&spChildDoc)))
{
CComBSTR bstrName;
if(SUCCEEDED(spWin->get_name(&bstrName)))
{
USES_CONVERSION;
char psz[100],*p;
memset(psz,' ',indent*3);
psz[indent*3]=0;
p=W2A(bstrName);
OutputDebugString(psz);
OutputDebugString(p);
OutputDebugString("\r\n");
}
EnumFrame(spChildDoc,indent+1);
}
}
}
VariantClear(&varDisp);
}
}
{
// TODO: Add your specialized code here and/or call the base class
IHTMLDocument2 * pDoc = NULL;
IHTMLWindow2 *pHTMLWnd = NULL;
IHTMLDocument2 * pFrameDoc=NULL;
IHTMLFramesCollection2 *pFramesCollection=NULL;
LPDISPATCH lpDispatch;
long p;
VARIANT varindex,varresult;
varresult.vt=VT_DISPATCH;
varindex.vt = VT_I4;
try
{
pDoc = (IHTMLDocument2*)(GetHtmlDocument());
if(pDoc!=NULL)
{
pDoc->get_frames(&pFramesCollection);
if(pFramesCollection!=NULL)
{
pFramesCollection->get_length(&p);
if(p>0)
{
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)))
{
CString info;
info.Format("%d",pFrameDoc);
MessageBox(info); pFrameDoc->Release();
pFrameDoc=NULL;
}
pHTMLWnd->Release();
pHTMLWnd=NULL;
}
}
}
}
}
}
}
catch(...)
{
};
try
{
if(pDoc != NULL)
pDoc->Release();
if(pFramesCollection != NULL)
pFramesCollection->Release();
}
catch(...)
{
}; CHtmlView::OnDocumentComplete(lpszURL);
}
<html>
<iframe name="iTestFrame" src="Test.html">hello world</iframe>
</html>
pFrameDoc地址。另外,从你反应的错误来看,可能是接口指针释放不当导致的,与安全性无关,对ie也是一样。
其实不但是iFrame甚至连Frame也会有问题:以下的javascript代码也会同样的错误:
这个是在 http://congling.com/frame.html的叶面
<html>
<iframe name="iTestFrame" src="http://localhost:8080/frameset.html">hello world</iframe>
<script language=javascript>
function Show()
{
alert(document.frames.iTestFrame.document.all.length);
//alert(document.location.href);
}
</script>
<input type=button onclick="javascript:Show()" value="Show Info"> </html>Reference:
Q167796 PRB: Permission Denied When Scripting Across Frames
在我这里你的方法的确不行,就是在
if(SUCCEEDED(hr=pHTMLWnd->get_document( &pFrameDoc)))错误,错误代码是: E_ACCESSDENIED,当时两个iFrame的域是sina.allyes.com以及2002.sina.com.cn
我不知道你那里为什么可以
IHtmlFrameBase2接口访问 ,我用的就是IE6,winxp。另外顺便说一句,sina首页太龌龊了,在winme下会不断开新窗口和广告,
我这段代码在ie5.5下访问它时不行了,但也没出错呀。
开主页和广告,我的方法在ie5.5下不行了。
Email: [email protected]