Recent searches


No recent searches

Close all tabs function

Answered


Posted Feb 20, 2014

I often end up with a load of tabs open and although the Ctrl Alt W will close  a tab it would be great to have a short cut to close all tabs

 


2

9

9 comments

I ran into this and created a bookmarklet to do this. It will close all tabs that do not have changes

javascript:(function(){$('#branding_header ul li').each(function(){ if(!$(this).hasClass('activity')){$(this).find('.close').click();}});})();

0


Worked a treat Andrew. I'd never used a bookmarklet till now so thank you. As I'm a noob to javascript would you mind explaining how the function works?

0


Hi, could anyone explain how to create this 'bookmarklet' please?

0


heres an explanation for anyone that's curious

 

Highlight the code then left click on it and slid your mouse up to your bookmark bar and drop it. Once you drag the code up there you can edit it to give it a easy name (i.e. Close ZD tabs). Then when you're within your ZD and have many tabs open simply click on the bookmark.

Works great, thanks Andrew!

0


I like it, but it creates an empty tab like this one here that cannot be closed:

When I click the bookmarklet a second time, I get a two of these tabs. Reloading Zendesk gets rid of them.

I use Chrome Version 60.0.3112.101 (Official Build) (64-bit)

0


This should work in Chrome (probably any other modern browser too) and prevents the issue Olaf describes.

javascript:(function () {[...document.querySelectorAll('li.tab .close')].reverse().forEach(btn => btn.click())})()
 
and if you want to close all but the selected tab:
 
javascript:(function () {[...document.querySelectorAll('li.tab:not(.selected) .close')].reverse().forEach(btn => btn.click())})()
 
And if you want to use it with a keyboard shortcut, you can use this user script I created:
 
 
Thanks Andrew for the inspiration

0


Jonathan Coleman

thanks for your shortcut version. Could you please advise how do I add it? As I understood this should be a part of the url address?

0


@Andriy

You will need to install an extension which allows user scripts. For example Tampermonkey for Chrome. From the extension, add a new script and copy/paste in the code.

The shortcut key combo I assigned in the script is CTRL + SHIFT + Z.

0


@Andrew - you just became my favorite person of the week. Please take two days off. Thank-You very much!! :D

0


Post is closed for comments.

Didn't find what you're looking for?

New post