您可以使用window.postMessage做这样的事情:
初始窗口的HTML文件:
<!DOCTYPE html>
<html>
<head>
<script>
var otherWindow;
function openOther() {
otherWindow = window.open("other.html", "otherWindow");
}
function otherFunc() {
otherWindow.postMessage("otherFunc", "*");
}
</script>
</head>
<body>
<div onclick="openOther()">Open the other window</div>
<div onclick="otherFunc()">Call the other window's function</div>
</body>
</html>
的HTML第二个窗口:
<!DOCTYPE html>
<html>
<head>
<script>
window.addEventListener("message", function(event) {
alert("The other window's function executed.");
}, false);
</script>
</head>
<body>
<div>This is the other window.</div>
</body>
</html>
这里有一个很好的参考为window.postMessage。
你可以运行一个小的静态网络服务器吗?这在Go或Node.js中是件小事。 – tjameson
我可以,但我真的只想双击.html文件。我目前正在主服务器上使用VirtualHost。 – Soumya