七种跨域方法【5.window.postMessage篇】
来源:互联网 发布:师洋的淘宝店铺是 编辑:程序博客网 时间:2024/06/03 07:48
问题描述:本地http://localhost/data.html向异域http://www.lamport.me/data2.html获取数据如果该文件不能访问,你可以在自己的wamp中配置一个虚拟主机进行访问虚拟主机的配置地址:http://blog.csdn.net/super_yang_android/article/details/53991982
http://localhost/data.html代码
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>window.postMessage</title> <script> /* * window.postMessage是html5中的方法 * */ window.onload = function () { var oInput = document.getElementById('input1'); var oButton = document.getElementById('btn1'); oButton.onclick = function () { var data = oInput.value; window.frames[0].postMessage(data, '*'); } } </script></head><body><iframe src="http://www.lamport.me/data2.html" style="display:none" frameborder="0"></iframe><input type="text" id="input1" value="你好,地球,我来自黑暗星球"><button id="btn1">点击我通过iframe框架向http://www.lamport.me/data2.html页面发送并返回数据</button></body></html>
异域http://www.lamport.me/data2.html代码
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>window.postMessage</title> <script> window.onmessage = function(e) { e = e || event; alert('我接受到来自外太空的数据:' + e.data); } </script></head><body></body></html>
0 0
- 七种跨域方法【5.window.postMessage篇】
- 知识点:window.postMessage
- window.postMessage跨页面通信
- JS跨域:window.postMessage + window.name +jsonp
- 使用window.postMessage实现跨域通信
- 使用window.postMessage实现跨域通信
- window.postMessage实现跨域通信
- 七种跨域方法【6.window.name篇】
- PostMessage()
- Postmessage
- postMessage
- PostMessage
- PostMessage
- PostMessage
- PostMessage
- PostMessage()
- PostMessage
- postMessage()
- Android之简单的开机动画
- Java Web架构知识整理——记一次阿里面试经历
- iOS之网络—— NSURLConnection、Runloop、NSURLSession、NSURLSessionDownloadTask
- android 调用系统相册并得到图片地址
- opengl superbible第一个程序
- 七种跨域方法【5.window.postMessage篇】
- python中的 read() readline()和readlines()
- 一个简单的linux命令——whereis
- 获取EXE或者DLL的版本信息
- jQuery中AJAX,$.post()与$.get()的区别
- Android viewpager滑动指示器,滑动卡片,
- 不经过docker hub 直接将别处的image 拷贝到相应机器
- hiveserver2服务异常停止java.lang.OutOfMemoryError: Java heap space
- Android adb shell启动应用程序的方法