| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 5 |
|
| 6 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 7 |
See the COPYING file for details. |
| 8 |
--> |
| 9 |
<head> |
| 10 |
|
| 11 |
<script type="text/javascript" src="../../../base.js"></script> |
| 12 |
<script type="text/javascript"> |
| 13 |
|
| 14 |
goog.require('goog.dom'); |
| 15 |
goog.require('goog.dom.TagName'); |
| 16 |
goog.require('goog.events'); |
| 17 |
goog.require('goog.net.xpc.CrossPageChannel'); |
| 18 |
|
| 19 |
</script> |
| 20 |
<script type="text/javascript"> |
| 21 |
|
| 22 |
var channel; |
| 23 |
var logEl; |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Writes a message to the log. |
| 28 |
* @param {string} msg The message text. |
| 29 |
*/ |
| 30 |
function log(msg) { |
| 31 |
logEl || (logEl = goog.dom.getElement('log')); |
| 32 |
|
| 33 |
var msgEl = goog.dom.createDom(goog.dom.TagName.DIV); |
| 34 |
msgEl.innerHTML = msg; |
| 35 |
logEl.insertBefore(msgEl, logEl.firstChild); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
goog.events.listen(window, 'load', function() { |
| 40 |
// Get the channel configuration from the URI parameter. |
| 41 |
var cfg = goog.json.parse( |
| 42 |
(new goog.Uri(window.location.href)).getParameterValue('xpc')); |
| 43 |
|
| 44 |
// Create the channel. |
| 45 |
channel = new goog.net.xpc.CrossPageChannel(cfg); |
| 46 |
channel.registerService('log', log); |
| 47 |
channel.connect(function() { |
| 48 |
log('Channel connected.'); |
| 49 |
}); |
| 50 |
}); |
| 51 |
|
| 52 |
</script> |
| 53 |
<style type="text/css"> |
| 54 |
body { |
| 55 |
background-color: #ddffff; |
| 56 |
font-family: arial,verdana; |
| 57 |
font-size: 12px; |
| 58 |
} |
| 59 |
</style> |
| 60 |
</head> |
| 61 |
<body> |
| 62 |
|
| 63 |
<h3><script type="text/javascript">document.write(location.href.replace(/\?.*/,'?...'))</script></h3> |
| 64 |
|
| 65 |
<p> |
| 66 |
<input type="text" id="msgInput" value="Hello from the iframe." |
| 67 |
style="width:250px"> |
| 68 |
<input type="button" value="Send" onclick=" |
| 69 |
channel.send('log', goog.dom.getElement('msgInput').value)"> |
| 70 |
</p> |
| 71 |
|
| 72 |
<div id="log" style="border: 1px #000 solid"></div> |
| 73 |
|
| 74 |
|
| 75 |
</body> |
| 76 |
</html> |