如何在BHO中操纵DOM

时间:2012-10-10 10:18:36

标签: c++ dom bho

我试图在我的BHO中操纵网站的DOM。我用C ++编写,但我无法弄清楚如何做到这一点。以下是我尝试过的不同方法。第二个不是真的操纵DOM,但我认为值得一试......

//get parent node
IHTMLDOMNode* parent;
ielem->QueryInterface(IID_IHTMLDOMNode, (void**)&parent);

//get child node
IHTMLElement* child_element;
doc2->createElement(L"a", &child_element);
IHTMLDOMNode* child_node;
child_element->QueryInterface(IID_IHTMLDOMNode, (void**)&child_element);

//Create Value
VARIANT value;
value.vt = VT_BSTR;
value.bstrVal = L"TEST";

//set value
child_node->put_nodeValue(value);

//append child
parent->appendChild(child_node, &child_node);

我尝试的另一种方式是:

//initialize
IHTMLElement* element;
BSTR* innerhtml;
ielem->QueryInterface(IID_IHTMLElement, (void**)&element);

//overwrite the content
element->put_innerHTML(L"<a href=\"http://www.google.de\">testytest</a>");
element->get_innerHTML(innerhtml);

//check for success
MessageBox(0, *innerhtml, L"Titel", 0);
delete innerhtml;

0 个答案:

没有答案