0
我正在製作Excel加載項Excel JavaScript API。此加載項中有一個按鈕,點擊它會啓動popup = window.open("https://localhost:3000/#/new/", "popup", "width=1000, height=1100")
並彈出瀏覽器窗口。重新加載彈出窗口後,Addin無法再接收postMessage
在彈出窗口中,我可以使用下面的代碼將消息發送給插件:
if ($window.opener !== null) {
alert($window.opener.location.href); // https://localhost/App/Home.html?et=
$window.opener.postMessage(msg, $window.opener.location.href);
}
而在插件,我可以使用下面的代碼從彈出收到消息:
function receiveMessage(event) {
console.log("RECEIVED: " + JSON.stringify(event.origin));
if (event.origin === ...) {
action(event.data);
}
};
所以它運作良好:當插件接收到消息時,它顯示RECEIVED: "https://localhost:3000"
。然而,我意識到如果我通過cmd+r
刷新彈出窗口,彈出窗口仍然可以發送消息($window.opener.location.href
仍然是一樣的),但插件不能再接收它; RECEIVED: "https://localhost:3000"
不再顯示。
有誰知道發生了什麼事以及如何解決它?
謝謝...我將嘗試下一個版本的Dialog API。對於這個版本,我想用window.open做最好的... – SoftTimur