Making It Work in Both Browsers!

Can it be done? Can these kinds of examples be made to work in two browsers? In fact, the answer is yes!

The key to this is realizing that you can use the differences. The difference you are going to use is the fact that in Internet Explorer an object known as document.all exists. So, if you use an if statement to test for this, you can find out whether you're dealing with Internet Explorer 5 or Netscape Navigator 4:

<script language="JavaScript">
<!-- Cloaking device on!
function someFunction()
{
if (document.all)
{
//Expression is true, so put IE5 statements here
}
else
//Expression is false, so put NN4 statements here
}
// Cloaking device off -->
</script>

Following this method, creating a super JavaScript ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.