header.gif (6771 bytes)

Lesson 10-More on image effects

Ok, continuing with our onMouseover/out example, in this section, we will look at:

Red_CurlyC035.gif (285 bytes)Presenting the final version of the onMouseover effects with the filter added in.

In order to add a filter to distinguish between the different versions of Netscape/IE, we need to look at a prebuilt object that helps us do that:

Navigator Object-Some properties of it.
appName This will provide you with the browser name of your browser: "Netscape" or "Microsoft Internet Explorer", for example.
appversion This will give you the version number of a browser. To make it harder on you, it doesnt return only the version number, but also the platform and country (U/I). ie: "3.01 (Win95;I)."

<html>
<head>
<script>
<!--
image01= new Image(42,42)
image01.src="1.gif"
image02= new Image(42,42)
image02.src="3.gif"
//-->
</script>

<script language="javascript">
<!--
function filter(imagename,objectsrc)
{
if ((navigator.appName=="Netscape")&&
(parseInt(navigator.appVersion)>=3))
document.images[imagename].src=eval(objectsrc+".src")
}
//-->
</script>

</head>


<body>
<a href="whatever.htm"
onmouseover="
filter('example','image02')"
onmouseout="
filter('example','image01')">
<img src="1.gif" name="example"></a>
</body>
</html>

Ok, by adding the filter, we have successfully prevented MS IE users from receiving error messages when surfing to your page. Lets discuss the details here:

After defining this function, we could use it over and over again with different images, by simply passing in a different image name and object path. This is where we should begin to realize that a little careful thought in programming can save us a lot of time afterwards. If we were to use the original coding for many images, even, assuming it is compatible with IE browsers, we would still be doing a lot more work than using a function, like above.

Red_CurlyC035.gif (285 bytes) Presenting an improved filter that is friendly to IE4.0 too

Now, the filter above screens out all IE browsers, which was how most filters did-however, that was because, until IE4.0, no IE browsers supported onMouseover effects. Now, with the advent of IE4.0, which happens to support onMouseover effects using the image object, we should update our filter to support it too! (Again, the reason why I didn't simply include that in the first filter was so that you could more clearly see how a filter works). The below filter, which should be used instead of the above, is IE4.0 friendly: The below onMouseover image  works with IE4.0 too:

Here is the filter code:

<script>
<!--
function filter(imagename,objectsrc)
{
var n=navigator.appName
var v=parseInt(navigator.appVersion)

var browsok=((n=="Netscape")&&(v>=3))
var browsok2=((n=="Microsoft Internet Explorer")&&(v>=4))
if ((browsok)||(browsok2))
document.images[imagename].src=eval(objectsrc+".src")
}
//-->
</script>

The above script will now be good to IE4.0 too, and only harass those lower level IE and NS browsers...

Like always, here is the complete image object:

image object
properties methods
border
complete
height
hspace
lowsrc
name
prototype
src
vspace
width
onAbort
onError
onLoad

And here's the complete navigator object:

Navigator object
properties methods
appCodeName
appName
appVersion
mimeTypes
plugins
userAgent
no methods

Lesson 11