分类: 系统运维
2017-07-12 17:45:21
data
传递的数据,在传递参数的时候需要使用JSON.stringify()方法将对象参数序列化
origin
目标的源,协议,主机,端口号
<body> <input type="button" value="点击发送数据到postmessage_01.html" onclick="sendInfoToAnotherDomain();"/> <iframe width="1200" src="">iframe> <script> function sendInfoToAnotherDomain(){ var personInfo= new Object; // 要发送的数据 personInfo.name='Yuelu';
personInfo.title='Hello';
personInfo.info="World"; var str=JSON.stringify(personInfo); // 获取iframe var iframe=window.frames[0]; /**
* [http description]
* @type {[type]} 要发送的数据, 目标url
*/ // 传递数据 iframe.postMessage(str,'');
} script> body>
次级页面(iframe)