最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to POST in window.open() - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited May 23, 2011 at 16:42 kapa 78.7k21 gold badges165 silver badges178 bronze badges asked May 23, 2011 at 16:39 VictorVictor 17.1k74 gold badges240 silver badges437 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

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)

  1. 暂无评论