Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to POST in window.open()

When we do a window.open(), is there an option to specify method = POST? Since by default, it is GET?

What I want is this. The parent window has some form parameters (many in number) and they should be sent to the server on window.open(). It is not a good idea to append all of them in the GET url using query string.

like image 474
Victor Avatar asked May 23 '11 16:05

Victor


1 Answers

You could use window.open() to open an empty window, with a name. Then you could use a <form> with a "target" attribute referring to that new window's name, and post it.

edit OK here's the idea. You have a form on the page, and it can be hidden:

<form id='theForm' method='post' action='/your/action' target='TheNewWindow'>
  <input type='hidden' name='param_1' value='whatever'>
</form>

Then you get the results into your window like this:

window.open('about:blank', 'TheNewWindow');
document.getElementById('theForm').submit();

Make sure that the window name you use is a valid identifier (like a JavaScript variable name), or IE will get upset.

Here is a jsfiddle.

like image 158
Pointy Avatar answered Sep 28 '22 21:09

Pointy