Click to See Complete Forum and Search --> : HELP! I'm having an issue with Javascript in Netscape.


emartin
03-14-2003, 12:52 PM
I am relatively new to javascript and am having a problem :(

I have a drop down box that when an option is selected, invokes a script that 'jumps' to the selected image. The following code works in IE, but not in netscape...

<form name="goto">
<td width="120">
<select name="image" onChange="location.href=goto.image.options[selectedIndex].value; window.close();" class="drop">
<option selected value="">Go To Picture:&nbsp;
<option value="javascript:view_album('http://www.mysite.com/cgi-bin/emAlbum/emAlbum.pl?album=2001 January Los_Angeles_Lakers_SMALL&image=1','150','188')">1) 1678931.jpg
<option value="javascript:view_album('http://www.mysite.com/cgi-bin/emAlbum/emAlbum.pl?album=2001 January Los_Angeles_Lakers_SMALL&image=2','475','594')">2) 1708303.jpg
<option value="javascript:view_album('http://www.mysite.com/cgi-bin/emAlbum/emAlbum.pl?album=2001 January Los_Angeles_Lakers_SMALL&image=3','475','594')">3) 1759413.jpg
<option value="javascript:view_album('http://www.mysite.com/cgi-bin/emAlbum/emAlbum.pl?album=2001 January Los_Angeles_Lakers_SMALL&image=4','475','594')">4) 570745.jpg
<option value="javascript:view_album('http://www.mysite.com/cgi-bin/emAlbum/emAlbum.pl?album=2001 January Los_Angeles_Lakers_SMALL&image=5','85','106')">5) 721666.jpg
<option value="javascript:view_album('http://www.mysite.com/cgi-bin/emAlbum/emAlbum.pl?album=2001 January Los_Angeles_Lakers_SMALL&image=6','100','125')">6) Kobe_prepa...
</select>
</td>
</form>

Any suggestion on how I can make it work in netscape!

Thanks,
Eric

Jona
03-14-2003, 12:56 PM
What about the actual view_album() function?

emartin
03-14-2003, 01:05 PM
The view_album() is in an external .js file that is fetched in the <head> of the page. It looks like:


function view_album(url, width, height) {

/* Initialize the variables.
aw/ah If JavaScript cannot determine the available height/width of the users screen,
these are the default window sizes that will be used if an image is too big to view.

sb "no" = do not use scrollbars, "yes" = use scrollbars. This is automatically determined below,
but if you prefer scrollbars, change this to "yes".

tp/lp tp - is the top position variable. It determines how far from the top the pop-up window will be
positioned. lp - is the left position variable. It determines how far from the left the pop-up
window will be positioned.

eh/ew eh - the extra buffer height around the image. The minimum value is 85.
ew - the extra buffer width around the image. The minimum value is 50.
*/
var mywin = null;
var path = url;
var opts = null;
var aw = 600;
var ah = 400;
var w = 0;
var h = 0;
var ew = 50;
var eh = 85;
var wWidth = 0;
var wHeight = 0;
var sb = "no";
var tp = 20;
var lp = 20;

// Get available screen width/height if possible.
if (typeof(screen.availHeight) != "undefined") { ah = screen.availHeight-tp-(eh/2);}
if (typeof(screen.availWidth) != "undefined") { aw = screen.availWidth-lp-(ew/2);}

// Set some values
w = parseInt(width);
h = parseInt(height);

// Set the window size buffer around the image. Change ew and eh above as needed.
wWidth = w + ew;
wHeight = h + eh;

// Set the minimum window width. Change wWidth = 450; as needed.
if (wWidth < 450) {wWidth = 450;}

// Set the maximum window size values if the image is bigger than the desktop.
if (wWidth > aw) { wWidth = aw; sb = "yes";}
if (wHeight > ah) { wHeight = ah; sb = "yes"; }

// The scrollbar option is configured above.
opts = 'scrollbars='+sb+', resizable=no, status=no, location=no, menubar=no, top='+tp+', left='+lp;
opts += ',height=' + wHeight;
opts += ',width=' + wWidth;

mywin=window.open(path,"",opts);

}


Thanks,
Eric

Jona
03-14-2003, 01:18 PM
You're right, it works in IE.... but I don't have Netscape on this computer. Gil Davis does, though. He should know.

gil davis
03-14-2003, 01:20 PM
<select name="image" onChange="location.href=goto.image.options[selectedIndex].value;window.close();" class="drop">This syntax is not specific enough for Netscape.<select name="image" onchange="location.href=this.options[this.selectedIndex].value" class="drop">I removed the window.close() because the location.href command will not have any time to execute, and it is illogical to change the window's location and then close the window. Surely that is not your intention.

Jona
03-14-2003, 01:26 PM
Told ya... :D

emartin
03-14-2003, 01:29 PM
Thanks Gil, I will try that out.

In the context of what I am doing, I invoke a script that opens a new window that is determined by the size of the image it is showing, so I do in fact want to close the existing window...does that make sense?

You can see an example at:
http://www.britneyimages.com/britneyimages/albums/

Thanks for the assitance...I will let you know if it works :D

Eric

emartin
03-14-2003, 04:35 PM
Thanks for everyone's help. The issue ended up being caused by a '\n' in a perl variable that was breaking up the code and causing netscape problems...

Its all working now...thanks again for the support!

Eric