{"id":54,"date":"2015-11-24T06:01:00","date_gmt":"2015-11-24T06:01:00","guid":{"rendered":"http:\/\/waynenguyen.org\/dev\/2015\/11\/24\/open-popup-window-while-sending-pos\/"},"modified":"2016-05-21T03:15:52","modified_gmt":"2016-05-21T03:15:52","slug":"open-popup-window-while-sending-pos","status":"publish","type":"post","link":"https:\/\/bruceng.com\/dev\/?p=54","title":{"rendered":"Open a popup window while sending post data"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\">\nIt&#8217;s actually very simple. It&#8217;s possible to create a form element and set the target to _blank so that upon submission the target will be opened in a new browser window\/tab.<br \/>\nUse hidden input elements to pass data to the target URL.<\/p>\n<p>&lt;form action=&#8221;&lt;target URL&gt;&#8221; method=&#8221;POST&#8221; target=&#8221;_blank&#8221;&gt;<br \/>\n&nbsp; &lt;input type=&#8221;hidden&#8221; name=&#8221;Name&#8221; value=&#8221;Wayne&#8221;&gt;<br \/>\n&nbsp; &lt;input type=&#8221;submit&#8221; value=&#8221;Click here to open the window&#8221;&gt;<br \/>\n&lt;\/form&gt;<\/p>\n<p>If &nbsp;you don&#8217;t want a button, use CSS to style the submit button to make it look like a hyperlink.<\/p>\n<p>If you use ASP.NET or SharePoint the framework may complain that there should be only one form tag in the page. In that case use Javascript to construct the form on the fly when the link is clicked, then get rid of the form element after the window is open.<\/p>\n<p>function openWindow()<br \/>\n{<br \/>\n var mapForm = document.createElement(&#8220;form&#8221;);<br \/>\n mapForm.style.display=&#8221;none&#8221;;<br \/>\n mapForm.target = &#8220;Map&#8221;;<br \/>\n mapForm.method = &#8220;POST&#8221;; \/\/ or &#8220;post&#8221; if appropriate<br \/>\n mapForm.action = &#8220;http:\/\/localhost:55079\/Default.aspx&#8221;;<\/p>\n<p> var mapInput = document.createElement(&#8220;input&#8221;);<br \/>\n mapInput.type = &#8220;text&#8221;;<br \/>\n mapInput.name = &#8220;test&#8221;;<br \/>\n mapInput.value = &#8220;Test Data&#8221;;<br \/>\n mapForm.appendChild(mapInput);<\/p>\n<p> document.body.appendChild(mapForm);<\/p>\n<p> map = window.open(&#8220;&#8221;, &#8220;Map&#8221;, &#8220;status=0,title=0,height=600,width=800&#8221;);<\/p>\n<p> if (map) {<br \/>\n  mapForm.submit();<br \/>\n }<br \/>\n \/\/delete the form element<br \/>\n mapForm.parentNode.removeChild(mapForm);<br \/>\n}<\/p>\n<p>&lt;a href=&#8221;#&#8221; onclick=&#8221;javascript:openWindow();&#8221;&gt;Click here to open window&lt;\/a&gt;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s actually very simple. It&#8217;s possible to create a form element and set the target to _blank so that upon submission the target will be opened in a new browser window\/tab. Use hidden input elements to pass data to the target URL. &lt;form action=&#8221;&lt;target URL&gt;&#8221; method=&#8221;POST&#8221; target=&#8221;_blank&#8221;&gt; &nbsp; &lt;input type=&#8221;hidden&#8221; name=&#8221;Name&#8221; value=&#8221;Wayne&#8221;&gt; &nbsp; &lt;input type=&#8221;submit&#8221; &hellip; <a href=\"https:\/\/bruceng.com\/dev\/?p=54\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Open a popup window while sending post data&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[24,20,19],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-http","tag-javascript","tag-web"],"_links":{"self":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=54"}],"version-history":[{"count":1,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":174,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions\/174"}],"wp:attachment":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}