Created
February 6, 2017 18:30
-
-
Save Raphhh/79cda2b328d049551b81e07a8356809e to your computer and use it in GitHub Desktop.
Close the current window in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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