I have a custom module with differents forms and on one of these forms i want to submit and open the result on a new tab. I found a way to do this on this link : custom form submit in a new browser tab

it works great but instead i need to make a js file to do the same thing.

If it works with the target attributes (link above) directly put in my form why make the same thing in a js file ? i suppose that i will have to use a js file, because with the target attributes it does not work, a new tab does not open when i clicked on a modal button (using ctools modal form).

So my problem is the following: when i make a js file and put this code

(function ($) {
Drupal.behaviors.multi_example = {
  attach: function(context, settings) {
      $('#pv-button').attr('target', '_blank');


It does anything ! On my js file, my id button works properly, i have tested it with a simple alert:

            alert("Hello World");

and it works. I've also tested with window.open('','_blank') and a new tab open. So i think there is a problem with the .attr() function. I've passed a long time to search a solution on "google" but nothing... i need some help please.

PS: I want to precise that i have used all these codes (code above) on a normal node, not on a modal.

I'm using Drupal 7.50, jQuery 1.10.2, PHP 5.6.19


This questions seems unrelated to Drupal, and is probably more appropriate on a different forum.

I'm no expert on HTML, but you should make sure that:

(a) you are applying the target attribute to html tags that accept it (basically <a> and <form> only). Notice that submit <button> or <input type='submit'> has a different attribute called formtarget (rather than target)

And (b) if you are applying this to an <a> tag, it has to also have an href attribute. See MDN reference

The link you posted for a "custom submit in a new browser tab" answer probably adds the target attribute to the <form> tag, not to the input.

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