190

I'd like (just to test some functions, after I'll avoid this behaviour) to load the page called by submit on a new tab : is it possible?

Community
  • 1
  • 1
markzzz
  • 45,272
  • 113
  • 282
  • 475

8 Answers8

389
<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
  • 17,809
  • 27
  • 91
  • 129
  • 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
42

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,609
  • 11
  • 12
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
  • 1,942
  • 2
  • 24
  • 26
17

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

nalply
  • 23,826
  • 12
  • 77
  • 96
ThiefMaster
  • 298,938
  • 77
  • 579
  • 623
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
  • 23,826
  • 12
  • 77
  • 96
SickHippie
  • 1,381
  • 8
  • 19
6

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
  • 291
  • 3
  • 12
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
2

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
  • 66
  • 5