{"id":1077,"date":"2010-06-14T18:58:22","date_gmt":"2010-06-14T13:28:22","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1077"},"modified":"2016-12-19T17:42:13","modified_gmt":"2016-12-19T12:12:13","slug":"how-to-send-a-post-request-in-window-open-function-of-javascript","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-send-a-post-request-in-window-open-function-of-javascript\/","title":{"rendered":"How to send a POST request in window.open() function of JavaScript."},"content":{"rendered":"<p>Hey,<\/p>\n<p>Recently, I need to show some printing stuff using window.open() method of JavaScript. I got stuck when the implementation demands sending POST call to the server for generating the print view.<\/p>\n<p>I googled a lot and found few JavaScript code snippets that provides some workaround for doing this stuff. Finally, I found some cool way for sending POST request in window.open(). I thought, it&#8217;ll be worth sharing.<\/p>\n<p>Here is the code:<\/p>\n<pre lang=\"html\"><form onsubmit=\"window.open(' ','myWindow','status=yes,scrollbars=yes,\r\nwidth=100,height=100')\" action=\"generatePrintMaterial.html\" method=\"POST\" target=\"myWindow\">\r\n...........................................................\r\n...................\/\/input fields.......................\r\n..........................................................\r\n<input name=\"Print\" type=\"submit\" \/>\r\n<\/form><\/pre>\n<p>Notice the name of the window (&#8216;myWindow&#8217;) is same as the name given in form&#8217;s <strong>&#8216;target&#8217;<\/strong> attribute. On submitting this form, javascript will open a new window and the output of the form will get rendered in that window.<\/p>\n<p>Hope this helps..<\/p>\n<p>~Chandan Luthra~<br \/>\nchandan(AT)intelligrape(DOT)com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Recently, I need to show some printing stuff using window.open() method of JavaScript. I got stuck when the implementation demands sending POST call to the server for generating the print view. I googled a lot and found few JavaScript code snippets that provides some workaround for doing this stuff. Finally, I found some cool [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":24},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1077"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1077"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1077\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}