简体   繁体   中英

Submit Form to New Window/Tab

I've wrote a simple 'add page' form to a small CMS I've built and I have a simple preview feature which submits a form and opens the front-end version of the page in a new window.

To achieve this up until now I've used:

<input type="submit" name="pagepreview" value="Preview" formtarget="_blank">

Apparently the formtarget which made this possible is depreciated (which I never actually knew) and it seems that Google may have removed this feature in their latest update as it's stopped working (but still works in Firefox).

What's my alternative here? The answers I've found all point back to formtarget or target but neither work any longer.

Ideally I'd want to avoid Javascript but if that isn't possible - how would I submit the form to a new window using Javascript or jQuery?

EDIT:

Apologies for not explaining well enough - I can't add the target attribute to the form as only one button allows a new window (the preview button) the others just submit on the same page. Javascript appears to be my only way to do this.

<form action="..." method="..." target="_blank">
   <input type="submit" name="pagepreview" value="Preview">
</form>

If you need to change the target dynamically:

 $('input[type="submit"]').click(function(event){
    var $this = $(this);
    var $form = $this.parents('form');
    $form.attr('target',$this.attr('formtarget'));
    $form.get(0).submit();
    event.preventDefault();
 });

like this: (add target = "_blank" )

<form action="" method="" target="_blank">
    <input type="text" />
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM