使用的是CHhtmlView
在OnDocumentComplete中,对一个正确的 IHTMLElement 对像可以使用 insertAdjacentHTML 操作。可是程序后期,比如加一个按钮。点一下更新提定的IHTMLElement节点 。其代码继续引用IHTMLElement 对像,但是使用 insertAdjacentHTML 却抛出了异常。下面是得到 IHTMLElement 对像,并更新的方法LPDISPATCH lpDisp = GetHtmlDocument(); CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spDoc(lpDisp);
CComPtr<IHTMLElement> spBodyElem;
HRESULT hr = spDoc->get_body(&spBodyElem);
if ( FAILED(hr) || !spBodyElem )
return; CComQIPtr<IHTMLDocument3, &IID_IHTMLDocument3> spDoc3(lpDisp);
if ( !spDoc3 )
return; CString strID( id ); //指定id
BSTR bID = strID.AllocSysString();
//使用id得到位置
CComQIPtr<IHTMLElement> spElemDetail;
hr = spDoc3->getElementById(bID, &spElemDetail);
SysFreeString( bID );
if ( FAILED(hr) || !spElemDetail)
return; BSTR BTxt;
spElemDetail->get_innerHTML(&BTxt); //在OnDocumentComplete 与 程序后期使用这语句都可以得到正确的值 BTxt = strTip.AllocSysString();
hr = spElemDetail->insertAdjacentHTML( L"beforeEnd" , BTxt ); //更新节点 ,此语句只有在OnDocumentComplete中才可以正常执行
SysFreeString( BTxt );
在OnDocumentComplete中,对一个正确的 IHTMLElement 对像可以使用 insertAdjacentHTML 操作。可是程序后期,比如加一个按钮。点一下更新提定的IHTMLElement节点 。其代码继续引用IHTMLElement 对像,但是使用 insertAdjacentHTML 却抛出了异常。下面是得到 IHTMLElement 对像,并更新的方法LPDISPATCH lpDisp = GetHtmlDocument(); CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spDoc(lpDisp);
CComPtr<IHTMLElement> spBodyElem;
HRESULT hr = spDoc->get_body(&spBodyElem);
if ( FAILED(hr) || !spBodyElem )
return; CComQIPtr<IHTMLDocument3, &IID_IHTMLDocument3> spDoc3(lpDisp);
if ( !spDoc3 )
return; CString strID( id ); //指定id
BSTR bID = strID.AllocSysString();
//使用id得到位置
CComQIPtr<IHTMLElement> spElemDetail;
hr = spDoc3->getElementById(bID, &spElemDetail);
SysFreeString( bID );
if ( FAILED(hr) || !spElemDetail)
return; BSTR BTxt;
spElemDetail->get_innerHTML(&BTxt); //在OnDocumentComplete 与 程序后期使用这语句都可以得到正确的值 BTxt = strTip.AllocSysString();
hr = spElemDetail->insertAdjacentHTML( L"beforeEnd" , BTxt ); //更新节点 ,此语句只有在OnDocumentComplete中才可以正常执行
SysFreeString( BTxt );
解决方案 »
- 怎么在输入对话框中添加对话框内容的 提示信息啊
- c++的try. catch是否能抓住所有的exception呢?
- VC6.0中连接SQL 怎么设置连接Timeout的时间?
- HANDLE 的问题,我在使用bmp的文件操作的时候,见有人使用HANDLE 来传递指针,请教一下!
- 什么方案能解决上传速度小的问题,言者有分,一共100,谢谢
- 我在一台A(WIN2000)上共享了一打印机,在另一台想电脑B上使用共享打印机有关的问题!!
- 那位给小弟一个羽化的算法,边缘模糊的效果也行.
- 如何知道某个DLL文件,是组件程序的DLL文件 还是普通的DLL文件?
- 求助,怎样编写一个显示“自己姓名”字样的程序。
- 菜鸟问:如何做一个登录网站时自动弹出的信息窗口???
- 关于ffmpeg解码h264 filter的问题
- 请教个内核对象句柄继承的问题
//Res/*You cannot insert text while the document is loading. Wait for the onload event before attempting to call this method. */这是msdn上说的,加载的时候不能用这个方法。
spElemDetail->get_innerHTML(&BTxt); //在OnDocumentComplete中 与 页面加载完成后主程序调用这条语句都可以得到正确的值但是使用 insertAdjacentHTML ,insertAdjacentText ,put_text 等改变 element 值的语句都无法使用了。只能在OnDocumentComplete 函数中使用。实在不懂怎么解决。