html5 postMessage 不起作用
即使我通过 postMessage 重复发送域消息,我的 window.addEventListener 函数也不会被触发。似乎根本没有收到任何回应。代码如下:
var myUrl = 'http://localhost:8085';
var newPopup = window.open( myUrl, '_blank', '' );
// Create listener
window.addEventListener('message',function(event) {
if (event.origin !== 'http://localhost:8085') return;
console.log('received response: ',event.data);
},false);
// Setup messenging
setInterval(function(){
var message = 'Hello! The time is: ' + (new Date().getTime());
console.log('blog.local: sending message: ' + message);
newPopup.postMessage(message,'http://localhost:8085');
},2000);
为什么侦听器不接收消息?
My window.addEventListener's function is not getting fired even when I repeatedly send the domain messages via postMessage. It's seems like it isn't receiving any response at all. Here is the code:
var myUrl = 'http://localhost:8085';
var newPopup = window.open( myUrl, '_blank', '' );
// Create listener
window.addEventListener('message',function(event) {
if (event.origin !== 'http://localhost:8085') return;
console.log('received response: ',event.data);
},false);
// Setup messenging
setInterval(function(){
var message = 'Hello! The time is: ' + (new Date().getTime());
console.log('blog.local: sending message: ' + message);
newPopup.postMessage(message,'http://localhost:8085');
},2000);
Why doesn't the listener ever pickup the messages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在错误的窗口上注册了处理程序。尝试
You are registering the handler on the wrong window. Try