1

How can I add a target="_blank" property to a menu item of type MENU_LOCAL_ACTION ? I cannot do 'options' on MENU_LOCAL_TASK, MENU_DEFAULT_LOCAL_TASK, and MENU_LOCAL_ACTION items. I tried with jQuery

(function($) {
    $(document).ready(function() {
        $('.page-admin-commerce-reports-incomplete-payments .action_links li a[href]').attr({
            target: "_blank",
            title: "Opens in a new window"
        })
    });
}(jQuery));

But it didn't work. Thanks!

0

There seems to be a module for this: Menu target.

In case you need to do it programmatically, you can have a look at the source code for inspiration. As far as I see, the module adds a special class to the menu items you select, and then some JS captures the click and opens a new window:

  $('a.target-blank', context).once('target-blank', function () {
    $(this).click(function() {
      window.open(this.href);
      return false;
    });
  });
| improve this answer | |
0

So I misspelled the class name! .action-links not .action_links My fault, the jQuery code worked fine.

| improve this answer | |
0

You could try Menu Attributes module. It works with Drupal 8 as far as I know

| 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.