I want to dynamically insert a form using JavaScript, and then submit it and open the target in a new window.
Here is my code:
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", xxx);
form.setAttribute("onsubmit", "window.open('about:blank','Popup_Window','scrollbars=yes,width=550,height=520');");
form.setAttribute("target", "Popup_Window");
document.body.appendChild(form);
form.submit();
This code works - it inserts the form dynamically and successfully submits the form. However, the form opens in a new tab, while I want it to open in a new window. Any idea what is going on? Any suggestions to fix this? I am also open to jQuery.
Thank!
EDIT: I'm not sure why people mark this as a duplicate. Yes, this is about the same topic as in the other question, but the answers are not related - the stated duplicate problem had a new line that messed up the code, I not only, but my code still won’t work ...
source
share