Skip to content

Instantly share code, notes, and snippets.

@jchip
Created October 26, 2018 15:42
Show Gist options
  • Save jchip/10d006c5ce5e5d22761f66f3d78e7181 to your computer and use it in GitHub Desktop.
Save jchip/10d006c5ce5e5d22761f66f3d78e7181 to your computer and use it in GitHub Desktop.
<html>
<head>
<script>
var baseUrl = "http://localhost:3000";
var launchedWindow;
function load() {
// window.location = "${baseUrl}";
console.log("launching")
}
function launch() {
if (typeof BroadcastChannel === "undefined") return load();
var bc = new BroadcastChannel(baseUrl);
setTimeout(load, 500);
function receiveMessage(evt) {
if (evt.data === "ping") {
console.log("got ping");
// open("", "_self").close();
window.open('', '_parent', '');
window.close();
bc.postMessage("pong");
} else if (evt.data === "pong") {
console.log("got pong");
// window.close();
}
}
bc.onmessage = receiveMessage;
bc.postMessage("ping");
}
launch();
</script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment