[英]Change div innerHTML through IHTMLDocument2 and C++
I'm trying to change the content of a div using IHTMLDocument2 interface this way: 我正在尝试使用IHTMLDocument2接口更改div的内容:
IHTMLElementCollection* collection = NULL;
IDispatch* mydiv;
doc2->get_all(&collection);
long count;
collection->get_length(&count); //just to check I get something
CComVariant varstr = L"mydivname";
CComVariant varint = 0;
collection->item(varstr, varint, &mydiv); //this works I get the div
IHTMLElement* htmldiv;
mydiv->QueryInterface(IID_IHTMLElement, (void**)&htmldiv);
CComBSTR html;
htmldiv->get_innerHTML(&html); //works too, I get the current content
HRESULT hr=htmldiv->put_innerText(L"hello"); //this does not work but returns S_OK
collection->Release();
So the content of my div is just cleared and not replaced with "hello", I don't understand why, can it be a security issue ? 因此,我的div内容仅被清除,而不是用“ hello”代替,我不明白为什么,这可能是安全问题吗?
Thanks 谢谢
According to the MSDN documentation , the string passed to put_innerText
is of type BSTR
. 根据MSDN文档 ,传递给
put_innerText
的字符串的类型为BSTR
。
So, I would suggest trying some code like this: 所以,我建议尝试这样的代码:
CComBSTR text(OLESTR("hello"));
hr = htmldiv->put_innerText(text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.