如何从C ++调用JavaScript函数?
要从C++调用JavaScript函数,请生成一个js文件,该文件将调用该函数。该网页将加载JS并且该函数运行-
int callId = 0;
void callFunction() {
//js文件
ofstream fout("generate.js");
fout << "caller(" << callId ++ << ", display);";
}
// code的HTML
<html>
<body>
<script>
var callId = 0;
function caller(i, func) {
if (callId < i ) {
callId = i;
func();
}
}
function display() {
alert("my Function called");
}
//loadjsscript
function loadScript(file) {
var myId = "gh";
var e = document.getElementById(myId);
if ( e != null )
e.parentNode.removeChild(e);
var script = document.createElement("script");
script.myId = myId;
script.src = file;
document.body.appendChild(script);
}
window.setInterval(function() {
//path tojs文件
loadScript("file:///path/generate.js");
}, 2000);
</script>
</body>
</html>热门推荐
9 庆双节祝福语简短
10 俄语祝福语贺卡文案简短
11 祖国生日祝福语简短英文
12 航空公司祝福语简短
13 送灯祝福语简短独特
14 生日牌祝福语英语简短
15 女朋友考试祝福语简短
16 公司开年仪式祝福语简短
17 新房开工吉日祝福语简短
18 春天变冷祝福语简短