简体   繁体   English

Javascript表单与目标一起提交到弹出窗口

[英]Javascript form submit to popup window with target

I Want to submit a form to a popup window (not blank). 我想将表单提交到弹出窗口(非空白)。 This works fine but for some reason my parentwindow is opened for a 2nd time. 这可以正常工作,但由于某种原因我的父窗口已第二次打开。

 var formelements = document.getElementById("exportform");
 formelements.removeAttribute("action");
 formelements.setAttribute("target","/path/exportwindow.html");
 exportwindow = window.open("/path/exportwindow.html", "myexportwindow", "width=800,height=600,resizable=yes");                                         

 formelements.submit();

HTML: HTML:

<form id="exportform" action="/path/myfunction" method="post">

So what happens is that the popup window opens and in the background my parent window is opened to a new tab. 因此,发生的情况是弹出窗口打开,并且在后台将父窗口打开到新选项卡。 Can anyone tell me why js is behaving like this? 谁能告诉我为什么js的行为如此?

The second parameter in window.open is the window name, and that must be the same as target window.open中的第二个参数是窗口名称,必须与目标名称相同。

 var formelements = document.getElementById("exportform");
 formelements.setAttribute("action","path/to/exportwindow.php");
 formelements.setAttribute("target","bugsme");
 exportwindow = window.open("", "bugsme", "width=800,height=600,resizable=yes");

 formelements.submit();

This opens a single popup, but you should probably not remove the action parameter but set it to the correct script receiving the form data 这将打开一个弹出窗口,但是您可能不应该删除action参数,而是将其设置为接收表单数据的正确脚本。

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

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