1 个回答

仔細一想發現必須處理跨域通信的問題。

www.a.com/login.html:

window.open("www.b.com/test.html")

window.addEventListener("message", function(event) {
    location.reload();
});

另一個域名下 www.b.com/test.html

window.opener.postMessage("hello", "*");

錯發到社區建設是因爲你一開始添加了 segmentfault 標籤。@Integ 這算不算 bug


這個不算社區建設吧。。。不過你不知道 window.opener.location.reload() 嗎?

<!DOCTYPE html>
<title>Self</title>

<button>Open</button>

<noscript>
    <button>Reload Opener</button>
    <script>
        document.querySelector("button").onclick = function(e) {
            window.opener.location.reload();
        };
    </script>
</noscript>

<script>
    document.querySelector("button").onclick = function(e) {
        window.open(window.URL.createObjectURL(new Blob([
            document.querySelector('noscript').textContent
        ], { type: "text/html" })));
    };
</script>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进