O'Reilly logo

The Book of JavaScript, 2nd Edition by thau!

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How Netscape Provides Browser-Specific Content

Now we've covered just about everything you need to know to understand how Netscape serves up the browser-specific content illustrated at the beginning of the chapter (Figure 3-1 and Figure 3-2). Here is a somewhat simplified and modified version of the JavaScript on Netscape's home page:

<script type = "text/javascript"> ❶ var agent = navigator.userAgent.toLowerCase(); ❷ var major = parseInt(navigator.appVersion); var minor = parseFloat(navigator.appVersion); ❸ var ns = ((agent.indexOf('mozilla') != −1) && (agent.indexOf('compatible') == −1)); ❹ var ns4 = (ns && (major == 4)); var ns7 = (ns && (agent.indexOf('netscape/7') != −1) ); var ie = (agent.indexOf("msie") != −1); var ie4 = (ie && (this.major ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required