Javascript assistance required please

Chris M.

Flashlight Enthusiast
Joined
Jan 17, 2001
Messages
2,564
Location
South Wales, UK
I havn`t ever worked with Javascript until today, there is still so much I have to learn in the realm of home made web design above and beyond basic HTML. However I am currently working (OK it`s been 3 years) on an updated version of one of my not-entirely-flashlight-related web sites and had the desire to incorporate a simple feature that would enable visitors to the site to switch between alternate image views in the same way Ebay`s photo hosting system works. I spent ages searching (tried reverse engineering the Ebay code too but gave up early on) and finally found something that looked promising. Spent about an hour fiddling with it to try and get it to do what I hoped, finally thought it was finished....until testing it with MSIE6. Normally I use Firefox 1.0x where it works marvellously. This script may have been written in the earlier days of MSIE and Netscape and as such, it works on the NS-based Firefox but stubbornly refuses in MSIE.

Get to the point will ya? OK. /ubbthreads/images/graemlins/tongue.gif

This page here: http://bulbmuseum.net/new/imagetest.htm is what I have so far. You click on any of the four buttons at the top and the large .GIF image should toggle between "Image 1", "Image 2" etc. Eventually those will be photographs and the buttons will be corresponding thumnails. Try it with Firefox and presumably older Netscape versions and it works, at least it does here. But not with MSIE6 at all. No idea about any other browsers yet either.

Hence this post. Are there any Javascript experts watching who could take a look at that code and suggest alterations that would make it work with all JS enabled browsers, especially MSIE? Just some updated syntax perhaps? If anyone can help then that will be great. Also any users of alternative browsers who could report on whether or not it works for you too? Cross platform compatibility is top on my priority list for web design, I don`t want this to be one of those sites that says "works with [Specific Browser] only" at the front door. I`m tempted to abandon the Javascript idea anyway but if it can be made to work for everyone, that would be great.

It does make a change for a site not to work properly in MSIE though. Usually it`s the other way around....


/ubbthreads/images/graemlins/grin.gif
 

Mednanu

Enlightened
Joined
Feb 16, 2003
Messages
333
Location
Earth...
[ QUOTE ]
Chris M.'s JS code said:

<font color="blue">function checkBrowser() {
if (navigator.appName == "Netscape" &&
parseFloat(navigator.appVersion) >= 3.0) {
return true;
}
else {
return false;
}
}
</font>

[/ QUOTE ]
Looks like you've told it to only perform the image swap if the browser IS Netscape. Believe it or not, several browsers report their identity as NS, hence, your page only works with these browsers due to the way you've defined your <font color="blue">checkBrowser</font> function.

You might want to change it to something more along the lines of:

<font color="blue">function checkBrowser() {</font> <font color="orange">if (document.images)</font> <font color="blue"> {
return true;
}
else {
return false;
}
}</font>


That way, your code just checks to make sure that the browser can do rollovers instead of restricting them to being displayed only to NS users ( or those whose browsers are reporting their appName as NS ).
 

Chris M.

Flashlight Enthusiast
Joined
Jan 17, 2001
Messages
2,564
Location
South Wales, UK
Thank you! /ubbthreads/images/graemlins/grin.gif - that works perfectly here now in both FF and MSIE. I spotted the browser check part but thought it was only to prevent it from trying to work with Netscape versions older than v3.0. Didn`t realise it locked out every other browser too. As I said, I`m new to Javascript, as of today. Just trying to expand the original script to work with four small images, and have them work as click-ons not mouse rollovers, was enough of a challenge.

Many thanks for your assistance! I have updated the original page, hopefully that`s all right now.

Users of other browsers are still invited to test and see if it`s good with Opera, Safari, older versions, etc as well. Incidentally a "more finished" version is here: http://bulbmuseum.net/new/sampleexhibit.htm but it is still *very* work in progress and liable to change quite a lot in layout and perhaps appearence.

/ubbthreads/images/graemlins/thumbsup.gif
 
Top