- basic scripting -

       Detecting Browsers
.   .   .

Like I said in Lesson #2, Microsoft Internet Explorer and Netscape Navigator do it two different ways. If you want to become a super duper dHTML programmer, you better learn both ways, or 1/4 of your visitors will be left in the dust. However, if it becomes too hard, just learn the Microsoft way because more people use it. So for a script to work, you must detect what browser the visitor is using, then have the script act accordingly. So here's how, stuffed into a script tag:


<script language="JavaScript">
<!--

function go() {

   var m = (document.all);
   var n = (document.layers);

   if (m) { alert("microsoft"); } else { alert("netscape"); }

}

//-->
</script>

And this script in action does this. The script first gathers information on which browser it is. Microsoft is (document.all). Netscape is (document.layers). Netscape is made up of layers. That information is gathered in the lines:

var m = (document.all);
var n = (document.layers);

Then in the next line, it says "if the browser is Microsoft, then alert('microsoft'). if not, then alert('netscape')." if (m) translates to "if Microsoft". The complete line:

if (m) { alert("microsoft"); } else { alert("netscape"); }

Now that I've confused you enough, let's begin to build a dHTML script! Here's the script in action:

Okay, this is a fairly simple script. Before I go over line by line what's happening here, let me generally explain. We have a picture. I've used the <span> tag, and made the picture an [object]. I've named this object "theObj". Then by using javascript, I accessed theObj's CSS properties, and then altered them.

To more understand what's happening, you need to know how to access the CSS properties.

next >>

.   .   .

  1. Introduction
  2. What, Exactly, is it?
  3. The [object]
  4. Detecting Browsers
  5. Accessing Properties
  6. Making a Script
  7. Making the Script in Netscape
  8. What to Change?
  9. Creating a Menu
  10. Scripting the Menu
  11. The Netscape Menu
  12. Last Words