96

How to enable confirmation alert box option before closing opened tab in chrome browser? Need to change setting? I couldn't find any such options in setting window.

2

9 Answers 9

148

If you click "Warn before Quitting" in the Chrome menu on Mac it'll do the trick. It'll make you hold command + Q to quit. Not sure on PC.

This was huge for me because closing a tab, command + W is right next to close the whole freaking browser command + Q. Made that mistake too many times!

This is what it looks like on MacOS Sierra: enter image description here

11
  • 69
    I cannot understand why they would put that option in the Chrome menu rather than putting it in preferences. Anyway, thanks for this, I would not have thought to look in that menu. Dec 11, 2014 at 19:00
  • 4
    Yeah, this is a setting, put it there. What nonsense. Mar 8, 2015 at 21:30
  • 10
    What about for Windows OS?
    – Bort
    Mar 21, 2015 at 0:52
  • 9
    Where exactly is this option? I can't find it under the hamburger icon, nor in Settings. Not sure if it's been moved in Chrome v45 for Windows. Sep 16, 2015 at 20:27
  • 7
    So they just added this feature for Macs only? Not only that, are there only Mac users on Superuser?
    – Asaf
    Apr 15, 2016 at 10:47
19

If you close multiple tabs in your Chrome there is an alert box asking to "Close all the tabs?"

Yes Chrome closes the tab if you are pressing the X button without any confirmation and it can be quite annoying if you accidently close it in order to do so. You can press CTRL + SHIFT + T To restore your previous session of all your tabs.

You could also look for a Chrome extension such as Windows Close Protector

6
  • Extension is working when closing browser. I need an option available in opera browser. I think chrome may not have such option. anyway thanks for your answer.
    – Kumar V
    Jan 21, 2014 at 11:16
  • 5
    This Extension does not work anymore. Pig Toolbox does not work, too. So after Chrome Toolbox was kicked "Doube-click to close" and "multiple-close"-warning are not possible anymore. This really sucks.
    – mgutt
    Aug 30, 2014 at 0:01
  • 3
    Click the 'Chrome' button in the top left of your screen when in Chrome and then choose the 'Warn Before Quitting' option. Feb 3, 2016 at 3:38
  • You can restore your previous tabs... when you're not in incognito mode... Feb 26, 2017 at 23:30
  • Please update the link. Mar 12, 2017 at 9:31
13

In my case the biggest problem is when I use ctrl-shift-W or ctrl-shift-Q. If you want to remap a shortcut:

  1. Go to chrome://extensions
  2. In the very bottom right, click keyboard shortcuts Keyboard shortcuts A
  3. Rebind Ctrl + Shift + W to something less annoying. In my case I bound it to open lastpass extension.

enter image description here

Also, FYI: Ctrl-Shift-T will reopen all your tabs

2
  • 2
    You, sir, are my hero of the day. I accidentally hit Ctrl+Shift+W at least once a week, and Ctrl+Shift+T never restores the windows to their original position (or monitor!). Mar 30, 2017 at 20:07
  • 1
    This is savior! Thanks. Keyboard shortcuts option can now be accessed by opening burger menu on the left side.
    – Himanshu
    Mar 1, 2019 at 7:13
12
+50

To prevent accidental closing of Google Chrome:

  1. Download and run NoClose (add it to the Startup folder if you want it to start with Windows).

  2. Press Ctrl+1 to enable/disable the close button for the currently active window.
    close button disabled

To prevent accidental closing of individual tabs:

  1. Install an extension that allows embedding custom JS to web pages. I used Page Modifier, but there are others available like JScript tricks and Custom JavaScript for websites.

  2. If you chose Page Modifier, create a new script and enter the following JS code from kbeezie.com:

    function PopIt() { return "Are you sure you want to leave?"; }
    function UnPopIt()  { /* nothing to return */ }
    
    $(document).ready(function() {
        window.onbeforeunload = PopIt;
        $("a").click(function(){ window.onbeforeunload = UnPopIt; });
    });
    
  3. Set the Applied to field to * so the script runs everywhere, and save it.
    confirm navigation from page

The script will only be executed on any new pages you visit thereafter. Already open tabs will need to be reloaded for the script to execute.

I haven't tested it extensively so it might not work for all web pages, but if you're good with code, you could probably tinker with it and fix the problems.

13
  • It works but it pops up for every tab, it would get annoying fast.
    – GinKin
    Feb 26, 2015 at 21:13
  • @GinKin Isn't that the idea? A confirmation popup before closing any tab?
    – Vinayak
    Feb 26, 2015 at 21:16
  • Not every tab, just when pressing the X to close the window, like how it works on Firefox.
    – GinKin
    Feb 26, 2015 at 21:19
  • @GinKin You mean when multiple tabs are open and you're closing Chrome?
    – Vinayak
    Feb 26, 2015 at 21:21
  • 2
    Exactly. (15 characters to comment)
    – GinKin
    Feb 26, 2015 at 21:24
3

I choose to trick "myself" on this. Open chrome, pin the first tab. That will eliminate the X button from that first tab :)

1
  • 2
    It does not prevent Ctrl-W from working... (ctrl-shift-t works for unclosing individual tabs...) Jul 18, 2016 at 10:16
2

I believe the closest thing to this feature in stock Chrome is "continue where I left off" under the "On startup" section in settings.

3
  • Yes. we can but i wrongly closed a payment page tab. so i can not reopen it as it will submit the payment second time.
    – Kumar V
    Jan 21, 2014 at 11:17
  • @kumar_v This would be a very bad payment site.
    – mgutt
    Jan 24, 2015 at 11:03
  • 1
    Continue where you left off does not work when you have multiple Windows open. (I had a case where I accidentilly hit Ctrl-Shift-w instead of Ctrl-w and for some reason, Ctrl-shift-t only opened the same tab multiple times, instead of recovering the window like normally) Jul 18, 2016 at 10:15
1

There is a "Chrome Toolbox" extension which is supposed to handle this, but it is no longer supported. So what I did on Mac OS is to change keyboard shortcut for quitting Chrome "Cmd-Q" to something which doesn't trigger accidentally (e.g. Ctrl-Cmd-Shift-Q) so I am sure I will never press it accidentally again.

To change this shortcut goto System Preferences > Keyboard > Shortcuts > App Shortcuts. Click on + sign, from App dropdown select "Google Chrome.app", for Menu Title type "Quit Google Chrome" and for shortcut, press a complex key combination.

1

An extension or a third-party software program to achieve this sounds like too much work. Some answers apply only to Mac while others requires you to add script runners in Chrome to inject a certain script in all pages which again causes a problem where the confirmation box is shown for all tabs.

I believe the need of most users here is that they want to protect the whole window from closing at once and not each tab. I have created a simple static HTML page with a bit of JavaScript that makes a confirmation box appear when the whole Window is about to close.

You can find the HTML page here (hosted on JSBin) : http://jsbin.com/pejejib

How to use it? The only requirement is that you have the page opened in Chrome always during a session so that whenever you have clicked on the "X" button or the keyboard shortcut to close the Chrome window, the script in the page I've created is run and asked for confirmation.

  1. You can bookmark it and open it as per your requirement - when you are about to go for a long browsing session and you want to prevent such accidents then this is the best option.
  2. If you don't want to bother opening it each time you open Chrome, you can go to the page > right click on the tab > pin tab. Now whenever your close the browser the pinned tab will automatically open the next time you open it.
  3. OR set it as one of your startup-pages in Chrome. (best option if you use startup-pages)

The benefits of this is:

  1. No installation or extension is required, this is just a simple HTML page
  2. Doesn't display the confirmation box multiple times i.e each for all tabs.
  3. You can create your own fork and use it the way you like

For transparency, this is the JavaScript code in the page -

window.onbeforeunload = function(e) {
  var dialogText = 'Are you sure you want to close the Window?';
  e.returnValue = dialogText;
  return dialogText;
};

Yes, that's all! Simple and straightforward.

-1

For Window-level confirmation I used software listed at https://www.raymond.cc/blog/prevent-program-closing-disabling-close-button/

  1. NoClose (did not work for me)
  2. WinTopMost (expensive, did not try)
  3. Actual Window Guard (not free, but has a trial and works, even on Chrome, can be configured with various process and or window filters)
  4. Actual Window Manager (same as above, but more expensive with more additional features)
  5. NoVirusThanks Process Protector (no trial, did not try)

So my choice was https://www.actualtools.com/windowguard/

1
  • So, standard question - why downvote without any comment? I think my answer is elaborate enough. Clicked wrong button? Or did you happen to own one of the software I described above? :P Jan 6 at 15:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.