简体   繁体   English

提交表格到新窗口/标签

[英]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. 我已经向构建的小型CMS编写了一个简单的“添加页面”表单,并且具有一个简单的预览功能,该功能提交表单并在新窗口中打开页面的前端版本。

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). 显然,实现这一目标的formtarget已过时(我从未真正知道),并且似乎Google可能已在其最新更新中删除了此功能,因为该功能已停止工作(但仍可在Firefox中使用)。

What's my alternative here? 我这里有什么选择? The answers I've found all point back to formtarget or target but neither work any longer. 我发现的答案都指向formtarget或target,但它们都不再起作用。

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? 理想情况下,我想避免使用Javascript,但如果无法做到这一点-我将如何使用Javascript或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. 抱歉,解释不够充分-我无法将target属性添加到表单中,因为只有一个按钮允许一个新窗口(预览按钮),其他按钮仅在同一页面上提交。 Javascript appears to be my only way to do this. Javascript似乎是我执行此操作的唯一方法。

<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" ) 像这样:(添加target = "_blank"

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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