mouseovers - mouseover errors in older browsers

They have: 6 posts

Joined: Jun 1999

Hello All,
I have a few javascript mouseovers on the page I am building. I have
test the page using Netscape 3.2, Netscape 4.x and IE 4.x and have had
no problems. However in Netscape 2 I have had errors. I suspect I would
get errors in IE3 also. Anyway my question is, What do I add to the
script so the older browsers will not try to run the script?

This is what I have below.

<SCRIPT LANGUAGE="JAVASCRIPT">

if (document.images) {

var howmuch2=new Image(80,25)
howmuch2.src="button_howmuch2.jpg"
var howmuch1=new Image(80,25)
howmuch1.src="button_howmuch.jpg"

I added the document.images line, which does stop errors until the mouseover occurs. Then I get errors again.
Is there something that I need to add to the below line which calls the mouseover so that the mouseover never happens

<A HREF="howmuch.htm" target="rightFrame" onMouseOver="document.howmuch.src=howmuch2.src" onMouseOut="document.howmuch.src=howmuch1.src"><IMG SRC="button_howmuch.jpg" NAME="howmuch" WIDTH="80" HEIGHT="25" ALT="how much"BORDER=0></A>

Thanks
Stephen

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

Putting mouseovers inside a function will make them easier in the long run. The one below will do the trick for that single image. You can make it work for multiple images by sending parameters.

function over_image()
{
if (document.images)
document.howmuch.src=howmuch2.src
}

function off_image()
{
if (document.images)
document.howmuch.src=howmuch1.src
}

<A HREF="howmuch.htm" target="rightFrame" onMouseOver="over_image()" onMouseOut="off_image()"><IMG SRC="button_howmuch.jpg" NAME="howmuch" WIDTH="80" HEIGHT="25" ALT="how much"BORDER=0></A>

See also:
http://www.pageresource.com/jscript/jhover.htm
Instead of the browser detection shown there, you can just use if (document.images) instead. Smiling

----------
Page Resource: http://www.pageresource.com
JavaScript City: http://www.javascriptcity.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.