postMessage 解决窗口跨域消息传递
来源:互联网 发布:淘宝自定义模板尺寸 编辑:程序博客网 时间:2024/05/22 10:49
现在跨域嵌套的网页通信现在有了新的解决办法了。
postMessage(data,origin)
data是要传递的数据
origin:指明目标窗口源,http://XX.com 这样的。
如果同源就/
如果传递任意*
父页面:
document.querySelector("#child").contentWindow.postMessage('getcolor','http://localhost:8038');
向iframe发送消息。
window.addEventListener('message',function(e){})
绑定接收
子页面:
window.addEventListener('message',function(e){
if(e.source!=window.parent) return;
var color=container.style.backgroundColor;
window.parent.postMessage(color,'*');
},false);
接收消息判断访问源和父级是否一样。
用parent访问父级并postMessage发回消息。源是*
0 0
- postMessage 解决窗口跨域消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- HTML5 postMessage解决跨域、跨iframe窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域和跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨窗口/跨域消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- html5 postMessage解决跨域、跨窗口消息传递
- HTML5 postMessage 跨域窗口信息传递
- 36. Valid Sudoku
- Android LayoutInflater深度解析 给你带来全新的认识
- 155.Evaluate the following SQL statement
- 1076 Forward on Weibo
- 关于Qt的字符编码问题
- postMessage 解决窗口跨域消息传递
- eclipse 调试之异常断点
- Andrew Ng 机器学习笔记(三)
- Intellj IDEA14上用Debug启动项目启动不了:Unable to open debugger port: java.net.SocketException "socket closed"
- iOS 开发怎么入门?
- 【Android】如何分享本地图片
- Unity: ExampleGameInput.cs
- arm-linux-gcc交叉工具链的安装和使用
- float的位操作