0
点赞
收藏
分享

微信扫一扫

CEF开发 webkit


<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>C++ 调用 JavaScript 函数</title>

    <script>
        function ShowCppInfo(info, age) {
            document.getElementById("txtInfo").value = info;
            alert("这是 C++ 发来的数据:" + info);
			alert(age);
        }
		
		function test()
		{
			//ShowCppInfo("xiaoli", 30);
			document.getElementById("mybutton").innerHTML = "xiaohe"
		}
    </script>
</head>
<body>
    <input id="txtInfo" type="text" /><button id="mybutton" onclick="test()">确定</button>
</body>
</html>

------------------------------------------------

WebKit是渲染引擎,Chromium是浏览器。
Chrome 是Chromium的稳定版

CEF是Chromium Embedded Framework的缩写,是个基于Google Chromium项目的开源Web browser控件,支持Windows, Linux, Mac平台

OnButtonPressed cef_button_delegate.h

https://github.com/fanfeilong/cefutil/blob/master/doc/CEF%20General%20Usage-zh-cn.md

Dom操作CEF中访问修改HTML DOM元素_安晓辉生涯——聚焦程序员的职业规划与成长

1.cef调用js函数

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>C++ 调用 JavaScript 函数</title>

    <script>
        function ShowCppInfo(info, age) {
            document.getElementById("txtInfo").value = info;
            alert("这是 C++ 发来的数据:" + info);
			alert(age);
        }
		
		function test()
		{
			ShowCppInfo("xiaoli", 30);
		}
    </script>
</head>
<body>
    <input id="txtInfo" type="text" /><button onclick="test()"></button>
</body>
</html>

CString strInfo(L"小于");
    strInfo.Format(_T("ShowCppInfo('%s', %d);"), strInfo, 20); //传递多个参数
    if (m_simpleHandler.get()) {
        CefRefPtr<CefBrowser> cefBrowser = m_simpleHandler->GetBrowser();
        CefRefPtr<CefFrame> cefFrame = cefBrowser->GetMainFrame();
        if (cefFrame)
        {
            cefFrame->ExecuteJavaScript(CefString(strInfo), cefFrame->GetURL(), 0);
        }
    }

打开指定URL

CString strPath;
	GetModuleFileName(NULL, strPath.GetBufferSetLength(MAX_PATH + 1), MAX_PATH);
	strPath.ReleaseBuffer();
	int pos = strPath.ReverseFind('\\');	
	strPath = strPath.Left(pos);
	CString strUrl = _T("file:///") + strPath + _T("/HtmlPage1.html");
	m_simpleHandler->GetBrowser()->GetMainFrame()->LoadURL(CefString(strUrl));

举报

相关推荐

0 条评论