I am getting this error if I turn my block caches on. I have traced back the origin back to Drupal core form.js but can't seem to see what's going on here. Any ideas?

Here is the debug:

form.js?v=7.56:69 Uncaught TypeError: $.cookie is not a function
at String.<anonymous> (form.js?v=7.56:69)
at Function.each (jquery.min.js?v=1.7.2:2)
at HTMLFormElement.<anonymous> (form.js?v=7.56:67)
at Function.each (jquery.min.js?v=1.7.2:2)
at $.fn.init.each (jquery.min.js?v=1.7.2:2)
at $.fn.init.$.fn.once (jquery.once.js?v=1.2:55)
at Object.attach (form.js?v=7.56:65)
at Object.<anonymous> (drupal.js?p3kpc3:76)
at Function.each (jquery.min.js?v=1.7.2:2)
at Object.Drupal.attachBehaviors (drupal.js?p3kpc3:74)

Update: I think I am isolated this problem to a webform in a block on the page. If I get rid of that form, the error goes away. Also, this error doesn't happen every single time. Sometimes I have to change browser or open in incognito for it to crash, and then it happens repeatedly.

I can see that jquery.cookie is there when it works. But when there is a crash and I see the page source it's not there, so somehow it seems it's failing to load and when it happens I get the error. I am using JQuery Update (1.7).

  • 1
    It might help to give the original error message, with line numbers etc. Do you have any custom code that might possibly be related?
    – rooby
    Feb 2, 2018 at 6:11
  • Hi @rooby, edited my question with the debug stack trace. Feb 3, 2018 at 12:51

1 Answer 1


This happens sometimes as $.cookie function is not supported. In those case you can try following approach.

Place this code in your JavaScript file

function setCookie(cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  var expires = "expires="+ d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";

function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for (var i = 0; i var c = ca[i];
  while (c.charAt(0) == ' ') {
    c = c.substring(1);
  if (c.indexOf(name) == 0) {
    return c.substring(name.length, c.length);
return "";

Then you can use, setCookie(cname, cvalue, exdays) and getCookie(cname) to use set and get cookie functionalities instead of $.cookie.

Hope this works.

  • 1
    There is at least a syntax error in the code shown in the answer. The answer should also explain why the OP needs that code. Drupal comes with the jquery.cookie.js file; it's not supported doesn't explain why the file is sometimes loaded and sometimes it's not loaded.
    – apaderno
    Feb 27, 2021 at 9:22

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.