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
