Use Vimium
We can use Vimium to change the shortcut to close current tab. By default Vimium uses x
to close current tab, we can also add ctrl+x
to close tab so it will also works for web site that Google Docs that has one big input area which will capture x
.
- Install Vimium for Chrome or for Firefox
- Go to chrome://extensions, find Vimium, go to its extension options, add
ctrl+x
to close the current tab.
Now we always use x
or ctrl+x
to close tab, for websites that we want to protect it from closing we can exclude x
, so x
or ctrl+x
would not work for these websites.
We can also move the page to a new window, or install it as a chrome web app.
JavaScript Bookmarklet
- Open chrome://bookmarks/, right click the top right icon and select Add New Bookmark
- Type “Don’t close me” as the name
- Copy the following javascript code as the URL
javascript:(function(){
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = 'It looks like you have been editing something. '
+ 'If you leave before saving, your changes will be lost.';
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
})();
Install Websites as Chrome App
We can install Progressive Web Apps (PWAs) as an app. The website will run independently, this can prevent accidentally close it.
We can use applicationize to install non-PWA website.