202

For testing, I'd like to load the page called by submit on a new tab. Is this possible?

Michael M.
  • 10,486
  • 9
  • 18
  • 34
markzzz
  • 47,390
  • 120
  • 299
  • 507

8 Answers8

418
<form target="_blank" [....]

will submit the form in a new tab... I am not sure if is this what you are looking for, please explain better...

Strae
  • 18,807
  • 29
  • 92
  • 131
  • 1
    the `jquery` tag confused me, i thought you were talking about an ajax request ;) – Strae Apr 18 '11 at 22:27
  • 4
    @nalply: Seriously? Most browsers DO use tabs everytime a website suggests them to use a new window (`target="_blank"`). And that's a good thing because pretty much nobody wants a website to open a new window and I don't think this default will ever change since pretty much every website uses `_blank` nowadays. – ThiefMaster Oct 21 '12 at 10:51
  • That's sweeping an important detail under the rug. `_blank` does not open a new tab. It is opening a new **window**, which mostly (but not always!!) default to opening a new **tab**. It depends on the configuration of the browser. Please see this **heavily** upvoted answer: http://stackoverflow.com/a/4907854/220060 – nalply Oct 21 '12 at 12:48
  • @nalply I can agree with you that that command open the link in a new *window*, but you have to agree with me that all the known browser today open new windows as *tabs*, so the result is the same. If the user configured the browser manually to open a new window, then is a choose *he did* and we can't do nothing to prevent this. – Strae Oct 22 '12 at 10:07
  • @Strae, okay, it's slowly dawning on me. I use tabs for years but I still thought that non-power users didn't yet discover tabs. – nalply Oct 22 '12 at 11:14
  • Technically youre right, but nowadays the only pages that i see to open as a window and not as a tab are ads – Strae Oct 22 '12 at 16:08
  • @DhavalPankhaniya why not? – Strae Apr 23 '19 at 23:28
  • This no longer works in Chome version 83+ - perhaps formtarget="_blank" on the button will work instead. – RedScourge May 29 '20 at 21:54
49

It is also possible to use the new button attribute called formtarget that was introduced with HTML5.

<form>
  <input type="submit" formtarget="_blank"/>
</form>
dragontree
  • 1,709
  • 11
  • 14
28

I have a [submit] and a [preview] button, I want the preview to show the print view of the submitted form data, without persisting it to database. Therefore I want [preview] to open in a new tab, and submit to submit the data in the same window/tab.

<button type="submit" id="liquidacion_save"          name="liquidacion[save]"          onclick="$('form').attr('target', '');"      >Save</button></div>    <div>
<button type="submit" id="liquidacion_Previsualizar" name="liquidacion[Previsualizar]" onclick="$('form').attr('target', '_blank');">Preview</button></div>  
juanmf
  • 2,002
  • 2
  • 26
  • 28
18

Add target="_blank" to the <form> tag.

nalply
  • 26,770
  • 15
  • 78
  • 101
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
9

Since you've got this tagged jQuery, I'll assume you want something to stick in your success function?

success: function(data){
    window.open('http://www.mysite.com/', '_blank');
}
nalply
  • 26,770
  • 15
  • 78
  • 101
SickHippie
  • 1,382
  • 1
  • 8
  • 20
8

Try using jQuery

<script type="text/javascript">
$("form").submit(function() {
$("form").attr('target', '_blank');
return true;
});
</script>

Here is a full answer - http://ftutorials.com/open-html-form-in-new-tab/

webtech
  • 311
  • 3
  • 13
4

This will also work great, u can do something else while a new tab handler the submit .

<form target="_blank">
    <a href="#">Submit</a>
</form>

<script>
    $('a').click(function () {
        // do something you want ...

        $('form').submit();
    });
</script>
Link
  • 86
  • 5
2

Your browser options must be set to open new windows in a new tab, otherwise a new browser window is opened.

ArtieJ
  • 29
  • 1