HTML Goodies: Script Tip: Week 14
WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
It's back to the big browser choice script and its catch-all last section. First off, if you need to refresh yourself on the script, here it is:
Last week we talked about the general concept of the script. It's saying that if the browser is this version and this type, then do this. But, at the very end of each of those little testing nuggets, is something that sets a strange variable, "r", to either one or two. Remember that? Take another look if you don't. If the browser is Navigator, then "r" is set to 1. An MSIE browser sets it to 2.
Why? It seems a bit silly to set something to 1 or 2 and then never bring it into play. If the browser is Netscape Navigator, then "r" is set to 1 and the script sends the user to a new page. Why even have that "r" variable if it is never going to be used?
Ah, but it isgoing to be used. What if your user is running an Opera, or Lynx, or Cello browser? Hmmmmm? Now we get into the catch-all at the end of the page. It looks like this:
//if browser is not Netscape or MSIE
//known versions go to text-based page.
You see, the author never does care if "r" is given a value. In fact, "r" will only come into play if it never gets a value. That's why this is a catch-all. If the browser is none of the above, then send it to the text-based page. That's very clever.
- An exclamation point (!) means "is not." This statement (r !=1) reads "r is not equal to 1."
- The double ampersand (&&) means "and." Remember that you required a double equal sign to represent "equals"? Same thing here. You require double ampersand characters to mean "and." In case you're wondering, a single ampersand means "and bitwise." It's too much to get into here.
Next Week: Setting Multiple Variables as the Script Goes Along
HTML Goodies 30-Step Primer Series
and take the knowledge home with you in
on your Web pages here!