Forum Moderators: coopster

Message Too Old, No Replies

How to call a page and open it in another window

         

Gian04

3:00 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



I know target=_blank in a text link will open the page in another window.

But how can I open a page in another window if the user click a submit button?

jatar_k

3:08 pm on Aug 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think you would have to use javascript

phranque

3:28 pm on Aug 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



use the target attribute of the form tag similarly and it should work:

<FORM ACTION="example.cgi" TARGET="_blank" METHOD="post">
<FORM ACTION="example.cgi" TARGET="FormResults" METHOD="post">
etc...

Gian04

3:41 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



I have tried that already before I post my question here. It doesnt work, it opens on the same window.

justgowithit

3:48 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



paste this into the <head>:

<script type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>

Then your button is:

<form>
<input name="Open" type="button" onclick="MM_openBrWindow('page_url_here','','width=45,height=45')" value="Open" />
</form>

justgowithit

3:51 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



... or for your submit button use type="submit"

Gian04

4:43 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



But I need to pass a hidden field to the new window, Similar to this one:

echo "<form action="new_window.php" method="post">";
echo "<INPUT type="hidden" name="var_name" value="XYZ">";
echo "<input type=submit value="Open" class=submit1 style="width: 90px">";
echo "</form>";

phranque

11:46 pm on Aug 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



perhaps this will work:

<html>
<head>
<script type="text/javascript">
function submitForm()
{
var myForm=document.getElementById("myForm");
myForm.target="_blank";
myForm.submit();
}
</script>
</head>
<body>

<form id="myForm" action="new_window.php" method="post">
<inout type="hidden" name="var_name" value="XYZ">
<input type=submit value="Open" class=submit1 onclick="submitForm()" style="width: 90px">
</form>

</body>
</html>