几种跨域的解决方式
2017-07-18 本文已影响0人
柚丶稚橙熟时
jsonp
http://js.jirengu.com/cenuxecevi/2/edit
CORS
http://js.jirengu.com/lateqotuno/1/edit
降域


a和b的域名不同,因此不能互相操纵DOM

通过降域设置后:

便可以跨域操纵了:

postMessage
窗口a
<script>
var aa = document.getElementById("a");
aa.addEventListener("input",function(){
window.frames[0].postMessage(this.value,"*");
console.log(12);
})
</script>
窗口b
<script>
var bb = document.getElementById("b");
window.addEventListener("message",function(e){
console.log(3333);
bb.value=e.data;
})
</script>
