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>
3
  • possible duplicate of JavaScript post request like a form submit Commented Jul 13, 2012 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. Commented Jul 13, 2012 at 10:54
  • I need to open it in new WINDOW. Commented Jul 13, 2012 at 11:26

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.