开发者

How to POST in window.open()

开发者 https://www.devze.com 2023-03-07 16:34 出处:网络
When we do a window.open(), is there an option to specify method = POST? Since by default, it is GET?

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开发者_如何学Python not a good idea to append all of them in the GET url using query string.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消