简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM