iframe可通过postMessage解决跨域、跨窗口消息传递

https://www.cnblogs.com/dorothyorsusie/p/6178599.html

1 //iframe传参给父级页面
2 function give_info(){
3     console.log("触发事件");
4     window.parent.postMessage(1,'*');
5 }
//接收值
window.addEventListener('message',function(e){ var color=e.data; document.getElementById('color').style.backgroundColor=color; },false);

  

猜你喜欢

转载自www.cnblogs.com/wanan-01/p/10709690.html