postMessage实现跨域密码代添
来源:互联网 发布:linux 启动进程 start 编辑:程序博客网 时间:2024/05/20 17:41
登录页需要的js代码
(function(){
window.addEventListener('message', function(event){// 通过origin属性判断消息来源地址
// if (event.origin == 'http://a.com') {
var dataStr = event.data;
// alert(event.origin);
//alert(dataStr); // 弹出"I was there!"
//alert(event.source); // 对a.com、index.html中window对象的引用
// 但由于同源策略,这里event.source不可以访问window对象
var data = eval('(' + dataStr + ')');;
console.log(data);
document.getElementById(data.nameId).value=data.name;
document.getElementById(data.passwordId).value=data.password;
document.getElementById(data.btnId).click();
//}
}, false);
})()
代添页面的js
<body>
<iframe id="ifr" src="http://192.168.33.1:8080/sitweb" width="100%"></iframe>
</body>
<script type="text/javascript">
window.onload = function() {
var ifr = document.getElementById('ifr');
var targetOrigin = 'http://192.168.25.228:8080/sitweb'; // 若写成'http://b.com/c/proxy.html'效果一样
// 若写成'http://c.com'就不会执行postMessage了
ifr.contentWindow.postMessage('{"nameId":"userId","name":"admin123","passwordId":"password","password":"123456","btnId":"sub"}', targetOrigin);
};
</script>
0 0
- postMessage实现跨域密码代添
- postMessage()实现跨域
- HTML5-postMessage实现跨域
- 使用window.postMessage实现跨域通信
- 用postMessage实现跨域通信
- 使用window.postMessage实现跨域通信
- window.postMessage实现跨域通信
- HTML5:使用postMessage实现Ajax跨域请求
- 利用HTML5的window.postMessage实现跨域通信
- HTML5之window.postMessage实现跨域传递消息
- window.name 结合postMessage api 实现跨域
- HTML5 postMessage+iframe实现文件跨域异步上传
- 利用HTML5的window.postMessage实现跨域通信
- HTML5之postMessage和setEventListener实现<iframe>跨域通信
- 跨域解决方案之postMessage
- 使用html5 postMessage和window.name实现多浏览器跨域
- 用postMesage实现跨域,并解决Failed to execute 'postMessage' on 'DOMWindow'
- html5的postmessage实现js前端跨域访问及调用解决方案
- ref 和 out
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 将字符串中的中文标点替换成英文标点
- 户外监测让谁来做最可靠?
- JS字符串操作
- postMessage实现跨域密码代添
- 未完成题目
- Maven常用命令
- Oracle中的正则替换【REGEXP_REPLACE】和正则like【REGEXP_like】
- WebPack
- AOP 之 6.6 通知参数
- MySQL 事务没有提交导致 锁等待 Lock wait timeout exceeded
- AngularJs页面数据不加载的解决思路
- Android 让EditText失去焦点避免自动弹出输入法