Close all tabs function



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

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

  • Marta

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

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

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

  • Jonathan Coleman

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

    javascript:(function () {[...document.querySelectorAll(' .close')].reverse().forEach(btn =>})()
    and if you want to close all but the selected tab:
    javascript:(function () {[...document.querySelectorAll(' .close')].reverse().forEach(btn =>})()
    And if you want to use it with a keyboard shortcut, you can use this user script I created:
    Thanks Andrew for the inspiration
  • 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?

  • Jonathan Coleman


    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.

  • Rich Hemmings

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


Post is closed for comments.

Powered by Zendesk