1.跨浏览器通讯之iframe 以及window.open
来源:互联网 发布:pl sql developer下载 编辑:程序博客网 时间:2024/06/10 13:50
同一域名下通讯:
1.iframe之间通讯:
效果以及代码:http://sandbox.runjs.cn/show/3ntvrlml
2.BOM对象实现通讯:
效果以及代码:http://sandbox.runjs.cn/show/owl7v6pm
3.HTML5 Web Workers
HTML5实现iframe:
域名为http://localhost:8080下的页面:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body><button id="ch">发送消息</button><iframe src="http://localhost:8080/HTML5/1/getMesage.html" frameborder="1" id="iframe"></iframe><script> document.getElementById("ch").onclick=function(){ /*实现效果 --当前页面的域名为http://127.0.0.1:8080/HTML5/1/postMessage.html --向域名为http://localhost:8080/HTML5/1/getMesage.html的iframe发送数据 //postMessage参数 //第一个是要发送的数据 //第二个是要发送目标的域名[需要携带http协议,需要和iframe的域名相同] */ document.getElementById("iframe").contentWindow.postMessage("1","http://localhost:8080") } </script></body></html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body><p>http://localhost:8080下的页面</p><script> window.addEventListener('message', function(ev) { //message事件的事件对象下保存了发送过来的内容 //ev.data : 发送过来的数据 //ev.origin //alert('我接收到了a.com页面发送过来的数据,内容是:' + ev.data); //alert(ev.origin); if (ev.data == '1') { document.body.style.background = 'red'; alert("命令来源:"+ev.origin) } }, false);</script></body></html>
代码解释:
var attr=open("xxx.html") //这里返回的是一个window对象,可以通过attr来获取新窗口的window下的属性节点,iframe同理
HTML5:Web Workers:http://blog.jobbole.com/30592/
1 0
- 1.跨浏览器通讯之iframe 以及window.open
- iframe总结 + window.open
- ie6 iframe onload window.open
- window.open 浏览器差异
- window.open被浏览器拦截
- window.open 浏览器拦截解决
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- window.showModalDialog以及window.open用法简介
- 【C#】面向对象基础—属性、方法、结构
- TP整合微信遇到的一系列问题
- unity学习阶段笔记
- leetcode:Spiral Matrix II 【Java】
- Xcode里一个工程(Project)多个项目(target)做版本控制讨论
- 1.跨浏览器通讯之iframe 以及window.open
- 华为oj 将真分数分解为埃及分数
- hdoj-5636===dfs枚举新增的路有木有走
- Java的集合详细总结
- Android中图片资源格式的转换
- CodeForces - 617B Chocolate (规律)
- 关于socket buffer size的调优
- java中的局部变量与成员变量
- 挑7