 |
| Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 9th, 2011, 02:41 PM
|
|
Authorized User
|
|
Join Date: Feb 2011
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
Button1 - Window1, Button2 - Window2
Hi,
Is it possible to open Win1 with button1 an win2 with button2?
<script type="text/javascript">
function open_win() {
window.open("http://www.wrox.com", "_blank", "toolbar=no, resizable=no, copyhistory=yes, width=400, height=400");
}
</script>
<body>
<form id="form1" runat="server">
<p>
<table cellpadding="0" class="style1">
<tr>
<td class="style2">
<input type="button" value="Button1" onclick="open_win()" /></td>
<td>
<input type="button" value="Button2" onclick="open_win()" /></td>
JimP
|
|

February 9th, 2011, 02:46 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What is Win1 and what is Win2? You could pass a value to the function and switch on that:
Code:
function open_win(windowToOpen) {
}
...
<input type="button" value="Button1" onclick="open_win('Win1')" /></td>
<input type="button" value="Button2" onclick="open_win('Win2')" /></td>
Then inside open_win you can use JavaScript's switch statement on windowToOpen to choose the correct URL and open the window.
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
JimP (February 11th, 2011)
|
|

February 9th, 2011, 03:09 PM
|
|
Authorized User
|
|
Join Date: Feb 2011
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
...I'll come back to you on this, I'm painting a room right now...:-)
JimP
|
|

February 10th, 2011, 06:55 AM
|
|
Authorized User
|
|
Join Date: Feb 2011
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
win1 and win2 is just to different windows...
....umh..., can u help me form that switch?
Not very good with Javascript...
JimP
|
|

February 10th, 2011, 07:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Different windows or different URLs? In the former case, you can simply pass the URL in the button's click instead if Win1 and Win2 and use that for window.open.
Take a look here for JavaScript's switch statement: http://www.google.com/#hl=en&sugexp=...aScript+switch
It gives you links to pages such as this one: http://www.w3schools.com/js/js_switch.asp
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
JimP (February 11th, 2011)
|
|

February 11th, 2011, 04:03 AM
|
|
Authorized User
|
|
Join Date: Feb 2011
Posts: 21
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
Hi,
Thank you Imar!
Now I am able to open two different windows:
<html>
<head>
<script type="text/javascript">
function open_win(windowToOpen)
{
window.open(windowToOpen);
}
</script>
</head>
<body>
<form>
<input type=button value="Open Window1" onclick="open_win('http://www.wrox.com')">
<input type=button value="Open Window2" onclick="open_win('http://www.vg.com')">
</form>
</body>
</html>
----------------------------------------------
But now I do not know how to put the specs (size, statusbar or not, ++), for the window.
I tryed to put the specs in both the button and in the script, but it do not work.
Do you have an suggestion?
Thanks
JimP
|
|

February 11th, 2011, 04:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You can pass them as arguments to your method:
... onclick="open_win('http://www.wrox.com', 200, 400)">
And then change your function to accept them:
function open_win(windowToOpen, width, height)
{
...
}
You can then build up the options by concatenating these values (e.g. ...height=' + height)
If you Google for "window open width height" and read the first 10 or 15 hits, you'll be knowing all you need and more on opening windows with JavaScript.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
JimP (February 11th, 2011)
|
|
 |