Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2006, 01:17 AM   PM User | #1
Whizzz
New to the CF scene

 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Whizzz is an unknown quantity at this point
New Browser Window

Hi,

Although I get by with coding for what I need on my web pages, and spend enormous amounts of hours doing so, I am now asking for some help.

I wish to call for a new window in a browser when clicking on the option value in the code below. This drop and go link list box works fine and it calls for the web page, but I need a new browser window to come up after clicking.

I tried 100, and I mean 100 things, and searched for tutorials but no luck.

Here's the code;

<select name="DropGoCombo0" onChange="GoNow0(this.form)" size=1>
<option value=http://pcchill.com/xcart/catalog/Seal-String-p-35.html>Seal String
<option value="4.html">test
<option value="5.html">test
<option value="" selected>(VIEW & ADD COOLING ACCESSORIES TO CART)
</select>



</BODY>
<script language="JavaScript">
<!--
function GoNow0(Form){
var i=Form.DropGoCombo0.selectedIndex;
var g=Form.DropGoCombo0.options[i].value;
if (g!="") parent.location=g;
}
//------>

</script>

</HTML>



Any help would be very much appreciated.


Last edited by Whizzz; 01-19-2006 at 01:22 AM..
Whizzz is offline   Reply With Quote
Old 01-19-2006, 03:16 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Code:
<select name="DropGoCombo0" onChange="GoNow0(this)" size=1>
<option value=http://pcchill.com/xcart/catalog/Seal-String-p-35.html>Seal String
<option value="4.html">test
<option value="5.html">test
<option value="" selected>(VIEW & ADD COOLING ACCESSORIES TO CART)
</select>
...
function GoNow0(oSel){
  var i = oSel.selectedIndex;
  var g = oSel.options[i].value;
  if (g!="") window.open(g, "_blank");
}
That will always open a new window even if a page is already open. If you want to open each file in its own new window, use this:
Code:
function GoNow0(oSel){
  var i = oSel.selectedIndex;
  var g = oSel.options[i].value;
  if (g!="") {
     var w = window.open(g, "popup"+i);
     w.focus();
  }
}
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 01-19-2006, 09:10 AM   PM User | #3
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Quote:
Originally Posted by glenngv
Code:
window.open(g, "_blank");
Interesting.
Tbh, maybe I've lead a sheltered life, but that's the first time I've seen markup target values used as an argument within the window.open method.
I had to quickly test it out for myself, just to be sure.

I would have expected js to treat a markup value - namely _blank - like a custom string literal (and reuse it), rather than 'understand' it and use it accordingly.

It's unlikely to make me start loving popups, but it's useful to know. So, ta.
Bill Posters is offline   Reply With Quote
Old 01-19-2006, 10:11 AM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
"_blank" in window.open method is treated by javascript as any other string literal. But it also understands that markup target values such as "_blank", "_self", "_top", "_parent" or any user-defined values function the same way in window.open.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 01-19-2006, 10:16 PM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
You can also set the fourth parameter of your window.open call to true or false to control whether to reuse an existing window or not.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-20-2006, 02:36 AM   PM User | #6
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Can you point me to a reference that says window.open has 4th parameter?
The way to reuse existing popup window is by using the same user-defined target name.
Code:
window.open(url1, "popup");
window.open(url2, "popup");
Both url1 and url2 will open in the same popup window named "popup".
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:14 AM.


Advertisement
Log in to turn off these ads.