1

I would like to open a new window with javascript and pass POST parameters to it. I've tried a lot of things.

My latest code looks like this so far, but not working (I haven't tried to pass post parameters but after it will work I can only add hidden input to make it work. I guess.):

<form method="POST" name="showgraph" onsubmit="javascript:window.open('graph.php', 'Graph', 'scrollbars=yes,titlebar=no,top=300,left=400');" action="javascript:void(0)">
<a href="#" onClick="document.showgraph.submit();">Show graph</a>
</form>
Ales
  • 515
  • 2
  • 7
  • 24
  • possible duplicate of [JavaScript post request like a form submit](http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit) – Rob W Jul 13 '12 at 10:53
  • Replace `action="javascript:"` with `action="graph.php"`, remove `onsubmit=...` and add `target="Graph"`. The form will be opened in a new tab/window, depending on the user's preference. – Rob W Jul 13 '12 at 10:54
  • I need to open it in new WINDOW. – Ales Jul 13 '12 at 11:26

2 Answers2

2

You need to create hidden form with target="_blank" and submit it with javascript. It is not possible to pass POST parameters using window.open method. For more details visit this link

Community
  • 1
  • 1
Rafael Sedrakyan
  • 2,171
  • 9
  • 31
  • 41
0

If you have control over the initial page, why not just creat JavaScript variables with PHP?

<script type="text/javascript">
<?php

foreach ($_POST as $key => $val)
{
    echo "var php_$key = $val;";
}

?>
</script>

Then, you can pass the js vars in the query string of the URL parameter of window.open.

Brian Warshaw
  • 21,296
  • 8
  • 50
  • 70