I have added this script in my Drupal 7 site to make the site remember the last clicked Quicktab and then open that tab on page reload:

// JavaScript Document
(function($) {

    Drupal.behaviors.quicktabsTabMemory = {
      attach: function(context, settings) {
        // The .each() is in case there is more than one quicktab on a page.
        $('.quicktabs-wrapper', context).each(function () {

          var $this = $(this);
          var wrapperID = $this.attr('id');

                var nid = settings.nordtec_klister['currentNid']; // getting the nid on the client side

          var $activeTabLink = $('.quicktabs-tabs li.active a', context);
          var activeTabLinkID = $activeTabLink.attr('id');

          // Use a unique cookie namespace for each set of Quicktabs, which
          // should allow for more than one set on a page.
          var cookieName = 'Drupal-quicktabs-active-tab-id-' + wrapperID + 'nid='+ nid;
          // Default cookie options.
          var cookieOptions = {path: '/'};

          // Click the tab ID if a cookie exists otherwise set a cookie for
          // the default active tab.
          var $cookieValue = $.cookie(cookieName);
          if ($cookieValue) {
            $('#' + $cookieValue).click();
          else {
            $.cookie(cookieName, activeTabLinkID, cookieOptions);

          // Set the click handler for all tabs, this updates the cookie on every
          // tab click.
          $this.find('ul.quicktabs-tabs a').click(function quicktabsCookieClickHandler() {
            $activeTabLink = $this.find('.quicktabs-tabs li.active a', context);
            activeTabLinkID = $activeTabLink.attr('id');
            $.cookie(cookieName, activeTabLinkID, cookieOptions);


This works as a charm, BUT ever since I added this I keep getting this message in the browser (Chrome)...

Bad Request Your browser sent a request that this server could not understand. Size of a request header field exceeds server limit.

...after maybe 1 or 2 working days of browsing the site, adding and editing content (many tabs open with different pages etc). I can only assume that it's not a coincidence that those error messages began to show soon after I added this script.

So my question is: What should I do in order to avoid those messages? Clear out all cookies after a certain time? I have tried to limit the cookie life time to 28800 seconds and also the garbage collector life time to that same value in settings.php:

ini_set('session.gc_maxlifetime', 28800);
ini_set('session.cookie_lifetime', 28800);

This helped some, the messages does not occur as often after this, but they do still happen once a week or so.

  • You're misdiagnosing your problem. That error has nothing to do with that script. It's a server error. Check your Drupal logs after you see the error, you should get more information there.
    – Jaypan
    Mar 20, 2018 at 15:17
  • Couldn't a corrupt cookie cause that fault? If I close and reopen the browser (or use another browser) it works fine again. There is nothing in the server logs (the server folks says so anyway). But you're right, I should check out the "recent log" the next time it happens.
    – TBJ
    Mar 20, 2018 at 15:21
  • It could, but Drupal can't help you with that @TBJ; your server is responsible for cookies in that respect
    – Clive
    Mar 20, 2018 at 15:40
  • OK I will talk to the server support again. Thanks.
    – TBJ
    Mar 21, 2018 at 6:34
  • The answer from the server support team is that the browser probably tries to re-use old cache-data over and over. In the end the amount of data in the request header exceeds a certain limit and the error message appears in stead of the page. Also, nothing is saved in the server logs about these errors.
    – TBJ
    Apr 27, 2018 at 7:59

1 Answer 1


Finally found the solution to my problem, in case anyone else makes the same mistake.

The problem with my cookie is this line from the code above:

var cookieName = 'Drupal-quicktabs-active-tab-id-' + wrapperID + 'nid='+ nid;

Cookie names cannot contain equal characters (or spaces, commas, semi-colons etc). That will create errors. So i simply changed "=" to "-" in my code line above, and the errors went away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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