2

I am setting a simple javascript cookie and checking it before firing a jquery ui dialog

(function ($) {
  Drupal.behaviors.setPopupConfig = {
   attach: function (context, settings) {
   if ($.cookie('modalServed') == null) {
    $.cookie('modalServed', 'yes');
    // build and show the dialog

I am adding the javascript with drupal_add_js in a hook_entity_load() in a module. In testing I've noticed that if I have a link element in the modal with a destination set to another place in the site with a potential modal dialog, the second dialog will fire before the cookie is set in the browser, which is not the intended behavior. I've tried adding weight and scope options to the drupal_add_js call, but it doesn't solve the problem. Is there another way to make sure the modal js only fires after the cookie is set?

  • I hope you are doing this after you got the GDPR consent. ;) – leymannx Oct 14 '18 at 9:33
  • This particular site was dead before GDPR implementation, the question is quite old, but this is a valid comment moving forward. – steve Oct 15 '18 at 17:25
1

The solution in this case was to set a path on the jquery.cookie

$.cookie('modalServed', 'yes', {path: '/'});
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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