Putting It All Together

Here's a script containing most of what's been presented in the chapter so far. The script in Figure 3-14 redirects users to one page if they're using an older version of Netscape (version 4 or earlier), another page if they're using an older version of Internet Explorer (version 5.5 or earlier), a third page for browsers it's unfamiliar with, and a fourth page for modern browsers it knows about.

I've broken the code into two blocks of <script> tags. The first sets up the variables and the second does the redirection.

Note

It's a good idea to declare variables at the top of your script. That way, if you want to change a variable later, you won't have to go hunting through a lot of HTML and JavaScript to find it.

Figure 3-14. Complete ...

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.