仔細一想發現必須處理跨域通信的問題。 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>
仔細一想發現必須處理跨域通信的問題。
www.a.com/login.html
:另一個域名下
www.b.com/test.html
:錯發到社區建設是因爲你一開始添加了 segmentfault 標籤。@Integ 這算不算 bug
這個不算社區建設吧。。。不過你不知道 window.opener.location.reload() 嗎?