Close all tabs function

Answered

9 Comments

  • Andrew Schreiner

    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();}});})();

    6
  • adam payne

    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
  • Marta

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

    0
  • Marta

    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!

    1
  • Olaf Doemer

    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
  • Jonathan Coleman

    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
    1
  • Andriy Ivakhov

    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
  • Jonathan Coleman

    @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.

    2
  • Rich Hemmings

    @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.

Powered by Zendesk