我有一个页面addin.html
。它可以通过异步通信交叉页面
popup = window.open("https://localhost:3000/#/posts/editor/", "popup")
弹出另一个页面editor
(这不一定在同一个域)然后,两页有每个一个监听器里,并可以通过
// listen:
function receiveMessage(event) {
document.getElementById("display").innerHTML = JSON.stringify(event.data);
}
window.addEventListener("message", receiveMessage, false);
// send:
function sendMessage() {
popup.postMessage("data", popup.location.href);
}
将数据发送到对方
editor
由ui-router
实现。
.state('editor', {
controller: 'EditorCtrl',
resolve: { init: [ ... ] },
...
};
app.controller('EditorCtrl', ['$scope', 'init', function ($scope, init) {
...
}]
我想现在落实就是当addin.html
弹出窗口editor
,它会发送一些数据editor
,并init
需要解决这一数据,加载页面的:首先,它加载页面的解析init
。editor
在收到来自addin.html
的数据之前可能会挂起。
有谁知道如何修改接收器和发送器(和别的东西)来做到这一点?
难道你不能通过URL参数传递这个初始数据吗? –
可能有很多数据,我怎么把它们嵌入'window.open'? – SoftTimur
没有太多的选择。如果数据太大,请使用服务器端会话来存储和检索数据。或使用POST发送数据。 – estus