OLD | NEW |
1 <html> | 1 <html> |
2 | 2 |
3 <head><title>Post message tests</title> | 3 <head><title>Post message tests</title> |
4 <script> | 4 <script> |
5 // Send a message to our opener, and it will reply. | 5 // Send a message to our opener, and it will reply. |
6 function postToOpener(msg, origin) { | 6 function postToOpener(msg, origin) { |
7 window.opener.postMessage(msg, origin); | 7 window.opener.postMessage(msg, origin); |
8 return true; | 8 return true; |
9 } | 9 } |
10 | 10 |
11 // Send a message to a window named "foo". | 11 // Send a message to a window named "foo". |
12 function postToFoo(msg) { | 12 function postToFoo(msg) { |
13 var w = window.open("", "foo"); | 13 var w = window.open("", "foo"); |
14 w.postMessage(msg, "*"); | 14 w.postMessage(msg, "*"); |
15 return true; | 15 return true; |
16 } | 16 } |
| 17 |
| 18 // Send a message to a subframe of window named "foo". |
| 19 function postToFooFrame(msg) { |
| 20 var w = window.open("", "foo"); |
| 21 w.frames[0][0].postMessage(msg, "*"); |
| 22 return true; |
| 23 } |
17 | 24 |
18 // Listen to incoming messages. | 25 // Listen to incoming messages. |
19 var receivedMessages = 0; | 26 var receivedMessages = 0; |
20 window.addEventListener("message", messageReceived, false); | 27 window.addEventListener("message", messageReceived, false); |
21 function messageReceived(event) { | 28 function messageReceived(event) { |
22 receivedMessages++; | 29 receivedMessages++; |
23 // Change the title to generate a notification. | 30 // Change the title to generate a notification. |
24 document.title = event.data; | 31 document.title = event.data; |
25 } | 32 } |
26 </script> | 33 </script> |
27 </head> | 34 </head> |
28 | 35 |
29 </html> | 36 </html> |
OLD | NEW |