2

我试图在我的 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;
4

0 回答 0