markzzz
markzzz

Reputation: 47945

Submit HTML form in a new tab

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

Upvotes: 219

Views: 230527

Answers (8)

juanmf
juanmf

Reputation: 2004

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>  

Upvotes: 28

dragontree
dragontree

Reputation: 1799

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

<form>
  <input type="submit" formtarget="_blank"/>
</form>

Upvotes: 57

Link
Link

Reputation: 86

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>

Upvotes: 4

webtech
webtech

Reputation: 329

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/

Upvotes: 9

Strae
Strae

Reputation: 19445

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

Upvotes: 448

SickHippie
SickHippie

Reputation: 1402

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');
}

Upvotes: 9

ThiefMaster
ThiefMaster

Reputation: 318488

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

Upvotes: 20

ArtieJ
ArtieJ

Reputation: 29

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

Upvotes: 2

Related Questions