window.open 副屏窗口
window.opener 主屏窗口
测试效果如下
zhu.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>主屏</title>
</head>
<body>
这里是主屏
<button onclick="daKaiFu()">打开副屏</button>
<button onclick="diaoYongFu('HelloWorld')">调用副屏函数</button>
<script>
var fu = "";
function daKaiFu(){
fu = window.open("fu.html","","fullscreen=1,secondscreen=1,screenindex=1");
}
function diaoYongFu(val){
if(!fu) {
alert("请先打开副屏");
return;
}
fu.fuFunction(val);
}
</script>
</body>
</html>
fu.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>副屏</title>
</head>
<body>
这里是副屏
<script>
function fuFunction(val){
alert("副屏的函数被调用了 值为:" + val);
}
</script>
</body>
</html>