标签:sed cors web localhost 通信 com body png document
通信方式有很多种:
今天先来看下窗口间的通信方式。
一般窗口通信分为三种:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <iframe id="myFrame" src="http://localhost:63342/XChart/Iframe2.html" width="600px;"></iframe><br /> 9 <input type="button" value="向子窗口发送数据" id="btn" /> 10 </body> 11 </html> 12 <script type="text/javascript"> 13 window.onload = function(){ 14 var myFrame = document.getElementById("myFrame"); 15 var oBtn = document.getElementById("btn"); 16 17 oBtn.onclick = function(){ 18 myFrame.contentWindow.postMessage("testData","http://localhost:63342"); 19 } 20 } 21 function parentWindowHandler(){ 22 alert("这是父窗口的方法,可以被子窗口调用"); 23 } 24 </script>
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <p>http://localhost:63342/XChart/Iframe2.html</p> 9 </body> 10 </html> 11 <script type="text/javascript"> 12 window.onload = function(){ 13 window.addEventListener("message",function(ev){ 14 alert("父窗口向子窗口发送的数据是:" + ev.data); 15 alert("数据来源是:" + ev.origin); 16 }) 17 } 18 19 </script>
标签:sed cors web localhost 通信 com body png document
原文地址:https://www.cnblogs.com/chenyajie/p/8928896.html