...

View Full Version : New Browser Window



Whizzz
01-19-2006, 01:17 AM
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.

:)

glenngv
01-19-2006, 03:16 AM
<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:

function GoNow0(oSel){
var i = oSel.selectedIndex;
var g = oSel.options[i].value;
if (g!="") {
var w = window.open(g, "popup"+i);
w.focus();
}
}

Bill Posters
01-19-2006, 09:10 AM
…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. ;)

glenngv
01-19-2006, 10:11 AM
"_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.

felgall
01-19-2006, 10:16 PM
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.

glenngv
01-20-2006, 02:36 AM
Can you point me to a reference that says window.open has 4th parameter? :confused:
The way to reuse existing popup window is by using the same user-defined target name.

window.open(url1, "popup");
window.open(url2, "popup");
Both url1 and url2 will open in the same popup window named "popup".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum