8

The modal isn't triggered by a link on the page which the user has clicked. The modal is triggered when the user arrives on the url.

Think of something like a disclaimer that pops up as soon as the user arrives on the url.

2

1 Answer 1

10

You can use the Drupal.dialog function for this.

For example:

var $myDialog = $('<div>My dialog text</div>').appendTo('body');
Drupal.dialog($myDialog, {
  title: 'A title',
  buttons: [{
    text: 'Close',
    click: function() {
      $(this).dialog('close');
    }
  }]
}).showModal();

See node.preview.js for another example.

Update: To use this with an AJAX request/response:

Drupal.ajax({
  url: 'some/path',
  success: function(response) {
    var $myDialog = $('<div>' + response.data + '</div>').appendTo('body');
    Drupal.dialog($myDialog, {title: 'Some title'}).showModal();
  }
}).execute();

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

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