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 ...

Get The Book of JavaScript, 2nd Edition 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.