每次a.html向b.html发送消息的时候会产生两个请求,其中一个是a.com/proxy.html向b.com/bproxy.html跳转产生的,另一个是b.html重新向a.html发起“连接请求”时产生的:
图6
最后简单看一下实测的几个测试页面代码: 代码片段一,a.com/a.html: 08 | <input id="txt_msg" type="text" /> |
09 | <input id="Button1" type="button" value="向b.com/b.html发送一条消息"onclick="sendMessage(document.getElementById('txt_msg').value)" /> |
14 | <script type="text/javascript"> |
16 | function showMsg(msg) { |
17 | document.getElementById("div_msg").innerHTML = msg; |
19 | function getMessage(data) { |
20 | showMsg("messageForm b.html to ProxyWin:" + data); |
22 | function sendMessage(data) { |
23 | if (null != proxyWin) { |
24 | proxyWin.getMessage(data); |
代码片段二,a.com/proxy.html: 06 | <div id="Div1">A.com/proxy.html</div> |
07 | <div id="div_msg"></div> |
08 | <script type="text/javascript"> |
10 | function showMsg(msg) { |
11 | document.getElementById("div_msg").innerHTML = msg; |
14 | function getMessage(data) { |
15 | showMsg("messageForm A.com/a.html:" + data + "<br/>两¢?秒?后¨®将?跳¬?转Áa到Ì?B.com/bproxy.html"); |
17 | setTimeout(function () { location.href = "<a href="http: |
20 | function sendMessage(data) { |
21 | topWin.proxyWin = window; |
22 | topWin.getMessage(data); |
25 | var search = location.search.substring(1); |
26 | showMsg("messageForm B.com/b.html:" + search); |
代码片段三,b.com/b.html 08 | <input id="txt_msg" type="text" /> |
09 | <input id="Button1" type="button" value="向A.com/a.html发送一条消息"onclick="sendMessage(document.getElementById('txt_msg').value)" /> |
12 | <iframe id="proxy" name="proxy" style="width: 600px; height: 300px"></iframe> |
13 | <script type="text/javascript"> |
14 | function showMsg(msg) { |
15 | document.getElementById("div_msg").innerHTML = msg; |
17 | function sendMessage(data) { |
18 | var proxy = document.getElementById("proxy"); |
19 | proxy.src="<a href="http: |
22 | sendMessage("connect"); |
24 | function getMessage(data) { |
25 | showMsg("messageForm a.html to ProxyWin:" + data); |
代码片段四,b.com/bproxy.html 07 | B.com/bproxy.html</div> |
10 | <script type="text/javascript"> |
11 | var parentWin = parent; |
14 | function getMessage() { |
17 | parentWin.getMessage(data); |
19 | document.getElementById("div_msg").innerHTML = "messageForm a.com/proxy.html:" + data; |
|