将表单提交到新的自定义大小窗口 [英] Submit form to new custom size window

查看:113
本文介绍了将表单提交到新的自定义大小窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道这是一个愚蠢的问题,但我无法找到具体问题的确切答案。我已经尝试将提交按钮更改为常规按钮并添加 onClick 事件...没有骰子。我正在尝试将表单提交到新的自定义大小的窗口(因此不是Chrome中的新标签等)。我已经得到它所以它在新窗口中打开新页面上提交的表单数据,但自定义大小的窗口也打开为空白页面。

So I know this is a dumb question, but I haven't been able to find a precise answer to my specific issue. I have tried changing the submit button to a regular button and adding an onClick event... no dice. I am trying to submit a form to a new, custom-sized window (so not a new tab in Chrome, etc). I have gotten it so it opens the submitted form data on the new page in a new window, but the custom sized-window is also opened as a blank page.

<form action="Upload.cfm" target="_blank" enctype="multipart/form-data" method="post" onSubmit="window.open('', 'mywindow3','left=0,width=900,height=600,z-index=20, resizable=yes, scrollbars=yes');">

如果我删除onSubmit javascript,它只会打开一个新标签(再次,不是我想要的) 。如果我删除 target =_ blank,它只会打开一个新标签。

If i remove the onSubmit javascript, it just opens a new tab (again, not what I want). If i remove the target="_blank", it just opens a new tab as well.

我真正想做的是让我的onSubmit事件中的 window.open 维度适用于提交的表单页面,而不是一个无关的空白页。

What I really want to do is have the window.open dimensions in my onSubmit event apply to the submitted form page, not an extraneous blank page.

推荐答案

你可以这样做:

正常设置操作,为目标属性设置自定义名称,并将按钮类型设置为按钮,而非提交(我们将通过javascript提交):

Set the action normally, set a custom name for the target attribute and set the button type to button, not submit (we will submit by javascript):

<form id="myform" method="post"  enctype="multipart/form-data" action="Upload.cfm" target="result">
    <input type="text" name="test" value="test">
    <button type="button" id="mybutton">Send</button>
</form>

将点击事件设置为按钮并在回调中,使用 window.open()打开窗口,并将第一个参数设置为表单的操作,将第二个参数设置为表单的目标以及尺寸和其他属性。然后提交表单!

Set a "click" event to the button and, in the callback, open the window with window.open() and set the first parameter as the form's action and the second parameter as the form's target as well as the dimensions and furthermore attributes. And then submit the form!

document.getElementById('mybutton').addEventListener('click', function(){
  window.open('Upload.cfm', 'result', 'width=300,height=300');
  document.getElementById('myform').submit();
});

我在最新的Firefox和Chrome中测试了这个。

I've tested this in latest Firefox and Chrome.

这篇关于将表单提交到新的自定义大小窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆