html5 undefined,HTML5的postMessage返回undefined

我试图做一个页面之间使用的postMessage跨域通信(上example1.com),这是对example2.comHTML5的postMessage返回undefined

当iframe中完成加载在同一页上的iframe它使用以下命令将postMessage发送到父页面:

parent.postMessage('hello parent','http://example1.com'); //这个命令的工作

在事件处理程序的postMessage在父页面(上example1.com),我送一个响应返回给使用下列功能的子页面(example2.com):

//this function is defined in example1.com:

function receiveMessage(event){

if (event.origin == "http://example2.com"){

console.log('Message Received from iframe'); //this line works

event.source.postMessage('hello to you too', event.origin); //this line does not work

}

}

出于某种原因,iframe中postMessage的事件处理程序未触发。

//this function is defined in example2.com

function receiveMessage(event){

if (event.origin == "http://example1.com"){ // I even tried removing this check to no avail

console.log('Message Received from parent'); //this line works

}

}

当父母试图发送消息给iframe时,它只是返回undefined。

任何帮助表示赞赏!

编辑:

我试图改变example1.com的receiveMessage事件下面一行:( '你好你太',event.origin)

event.source.postMessage;

这样:

event.source.postMessage( '向你问好太', 'http://example2.com');

但我得到这个以下错误:

为什么event.origin评估,以http://example1.com当从example2.com接收消息?

example1.com正试图发送一个postMessage。这应该是错误的来源

2012-11-03

Kiran

+0

1)浏览器? 2)“家长”评估什么? –

+0

你说“从父母那里收到的信息”是有效的 - 那么这个非工作线实际上不起作用? –

+0

1)Chrome v22.0.1229.94。 2)在控制台中对父窗口进行评估,即example1.com –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值