小弟是cef菜鳥,不知道如何參考下面這個函式,也就是說CefBrowser::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(client),
"http://www.baidu.com",browserSettings);后如何獲得這個CefRefPtr<CefDOMDocument> document),懇請大神幫忙
void DomVisitTestor::TestModify(CefRefPtr<CefDOMDocument> document)
{
OutputDebugStringW(L"DomVisitTestor::TestModify\r\n");
CefRefPtr<CefDOMNode> bodyNode = document->GetBody();
if (bodyNode->HasChildren())
{
CefRefPtr<CefDOMNode> childNode = bodyNode->GetFirstChild();
wchar_t szLog[512] = { 0 };
do{
swprintf_s(szLog, 256, L"node name -%s,tagName-%s type-%d, value-%s\r\n",
childNode->GetName().ToWString().c_str(),
childNode->GetElementTagName().ToWString().c_str(),
childNode->GetType(), childNode->GetValue());
OutputDebugStringW(szLog);
if (childNode->IsElement() && childNode->GetElementTagName() == "H1"
&& childNode->GetElementAttribute("id") == "hello")
{
CefRefPtr<CefDOMNode> textNode = childNode->GetFirstChild();
swprintf_s(szLog, 512, L"found hello, text - %s\r\n", textNode->GetValue().ToWString().c_str());
OutputDebugStringW(szLog);
textNode->SetValue("Hello World Modified!");
break;
}
} while ((childNode = childNode->GetNextSibling()).get());
}
CefRefPtr<CefDOMNode> hello = document->GetElementById("hello");
if (hello.get())
{
hello->SetElementAttribute("align", "center");
OutputDebugStringW(L"Change hello align\r\n");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/133297.html
標籤:網絡編程
上一篇:關于QQ登錄視窗翻轉特效的實作。
