UNPKG

chronosjs

Version:

JS Channels Mechanism

62 lines (58 loc) 1.81 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Courier Tests</title> <script type="text/javascript" src="../dist/PostMessageCourier.js"></script> <script type="text/javascript"> var host = (window === window.top); var ignorePorts = ["80", "443", "0", ":"]; var protocol = window.location.protocol + "//"; var hostname = window.location.hostname === "localhost" ? "127.0.0.1" : "localhost"; var port = (-1 === ignorePorts.indexOf(window.location.port.toString())) ? ":" + window.location.port.replace(":", "") : ""; var channel = new Chronos.Channels(); var target; if (host) { target = { url: protocol + hostname + port + "/chronosjs/debug/courier.html", style: { width: "100px", height: "100px" } }; } var lpcourier = new Chronos.PostMessageCourier({ eventChannel: channel, target: target }); </script> </head> <body> <button id="SendEvent">Send</button> <script type="text/javascript"> var btn = document.getElementById("SendEvent"); btn.onclick = function() { if (host) { lpcourier.trigger({ appName: "HostAppName", eventName: "HostEvent", data: { text: "Text of the event" } }); } else { lpcourier.reply({ appName: "FrameAppName", eventName: "FrameEvent", data: { text: "Text of the event" } }, function(data) { alert(data); }); } }; </script> </body> </html>