思路很简单,在页面加载完成时,执行以下JS代码即可:
var v = document.createElement('script');
v.src='http://127.0.0.1:9526/cef.js';
document.body.appendChild(v);
cef.js文件内容:
alert('hello cef.js');
// 具体实现代码如下,重载OnLoadEnd即可
class SimpleHandler : public CefClient,
public CefDisplayHandler,
public CefLifeSpanHandler,
public CefLoadHandler {
public:
SimpleHandler();
~SimpleHandler();
// ...
virtual void onl oadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE
{
frame->ExecuteJavaScript("alert('OnLoadEnd');", frame->GetURL(), 0);
const CefString js = "var v = document.createElement('script');v.src='http://127.0.0.1:9526/cef.js';document.body.appendChild(v);";
frame->ExecuteJavaScript(js, frame->GetURL(), 0);
}
// ....