How to send a POST request in window.open() function of JavaScript. « Intelligrape Groovy & Grails Blogs

How to send a POST request in window.open() function of JavaScript.

Posted by Chandan Luthra

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 way for sending POST request in window.open(). I thought, it’ll be worth sharing.

Here is the code:

<form onsubmit="window.open(' ','myWindow','status=yes,scrollbars=yes,
width=100,height=100')" action="generatePrintMaterial.html" method="POST" target="myWindow">
...........................................................
...................//input fields.......................
..........................................................
<input name="Print" type="submit" />
</form>

Notice the name of the window (‘myWindow’) is same as the name given in form’s ‘target’ attribute. On submitting this form, javascript will open a new window and the output of the form will get rendered in that window.

Hope this helps..

~Chandan Luthra~
chandan(AT)intelligrape(DOT)com

http://in.linkedin.com/in/luthrachandan

http://twitter.com/chandanluthra

  • Share/Bookmark
This entry was posted on June 14th, 2010 at 6:58 pm and is filed under Javascript/Ajax/JQuery . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply