Piotr Piotr - 5 months ago 19
Javascript Question

JavaScript - Form submit to window.open popup not working IE/FF

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("target" , "previewWindow")
form.setAttribute("action", "partner_api/preview.php");

var pidField = document.createElement("input");
pidField.setAttribute("type", "hidden");
pidField.setAttribute("name", "pid");
pidField.setAttribute("value", "<?php echo $partnerID; ?>");
form.appendChild(pidField);

var bidField = document.createElement("input");
bidField.setAttribute("type", "hidden");
bidField.setAttribute("name", "bid");
bidField.setAttribute("value", boxID);
form.appendChild(bidField);

window.open('', 'previewWindow', 'width=235,height=500,left=100,top=100');
form.submit();


Hi,

I have problem with code above - it does work prefectly on Chrome, but doesn't on Firefox and IE.
What is supposed to do, is to submit created form to new popup window, but on FF/IE it just leaves blank window.

Is there any fix to that?

Answer Source

I actually found solution - if anyone needs it. It is required to add form to document to make it work. document.documentElement.appendChild(form); It fixed the issue on IE/FF