Skip to content

Instantly share code, notes, and snippets.

@Raphhh
Created February 6, 2017 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raphhh/79cda2b328d049551b81e07a8356809e to your computer and use it in GitHub Desktop.
Save Raphhh/79cda2b328d049551b81e07a8356809e to your computer and use it in GitHub Desktop.
Close the current window in javascript
function killMe(event) {
if (event.data === 'kill_me') {
event.source.close();
}
}
if (window.addEventListener){
addEventListener('message', killMe, false);
} else {
attachEvent('onmessage', killMe);
}
if (window.parent) {
window.parent.postMessage('kill_me', '*');
}
window.open(window.location.href, '_new', 'resizable,width=800,height=400');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment