最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Submit Form to New WindowTab - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share edited Oct 10, 2013 at 12:46 0Neji asked Oct 10, 2013 at 12:11 0Neji0Neji 1,1281 gold badge16 silver badges40 bronze badges 4
  • 1 and changing formtarget to target? – Alexander_F Commented Oct 10, 2013 at 12:12
  • @Fincha - I get the same problem unfortunately. – 0Neji Commented Oct 10, 2013 at 12:47
  • "Apparently the formtarget which made this possible is depreciated (which I never actually knew) " — It isn't. – Quentin Commented Oct 10, 2013 at 12:49
  • @Quentin - Oh, a quick Google led me to believe otherwise hence my assumption about Google maybe removing this. – 0Neji Commented Oct 10, 2013 at 12:51
Add a ment  | 

2 Answers 2

Reset to default 5
<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>
发布评论

评论列表(0)

  1. 暂无评论