Is it possible to close browsers, using JavaScript, PHP, or HTML without a prompt?
I was using this answer: How can I close a browser window without receiving the "Do you want to close this window" prompt?
I was using Internet Explorer but it has since been updated to version 10 (soon to be updated to 11) and this exploit does not work.
If there is a solution in a different (but updated) browser, that could work as well.
Is it possible to close browsers, using JavaScript, PHP, or HTML without a prompt?
I was using this answer: How can I close a browser window without receiving the "Do you want to close this window" prompt?
I was using Internet Explorer but it has since been updated to version 10 (soon to be updated to 11) and this exploit does not work.
If there is a solution in a different (but updated) browser, that could work as well.
Share Improve this question edited May 23, 2017 at 11:59 CommunityBot 11 silver badge asked Jul 17, 2014 at 15:01 jlrosenbergjlrosenberg 2874 silver badges14 bronze badges 3- 4 Could you elaborate on why you want to do this? As the current answer says, in general, a page that does this is incredibly rude, and I'm very happy that browsers don't allow it. But perhaps you have a good reason, and depending on that reason, another approach may work very well for you. – user743382 Commented Jul 18, 2014 at 7:16
- @hvd: Ever seen those "Close Window" buttons? It would be kinda ridiculous for them to ask you to confirm. – user541686 Commented Jul 20, 2014 at 9:28
- @Mehrdad I've only seen them in pop-up windows where the browsers already don't ask for confirmation. If that were what the OP wanted to use it for, we wouldn't be reading this question. – user743382 Commented Jul 20, 2014 at 9:50
2 Answers
Reset to default 12- HTML can't do anything programatic. It's just markup.
- PHP can only do programatic stuff at your server, not the browser, so no solution there either.
- Finally, you cannot do it in JS either (unless it's a window opened by a script).
Imagine visiting a web site that closed your browser and you lost all of your open tabs.
There are different hacks for different browsers. This code is based on the one here with a small adjustment to the last else
block to work on IE 11. I suggest you test it on other IE versions and see if it needs more tweaking.
function closeWindow() {
var Browser = navigator.appName;
var indexB = Browser.indexOf('Explorer');
if (indexB > 0) {
var indexV = navigator.userAgent.indexOf('MSIE') + 5;
var Version = navigator.userAgent.substring(indexV, indexV + 1);
if (Version >= 7) {
window.open('', '_self', '');
window.close();
}
else if (Version == 6) {
window.opener = null;
window.close();
}
else {
window.opener = '';
window.close();
}
}
else {
window.open('', '_self', '');
window.close();
}
}