- Detecting Browser Plug-ins
- Around and Around with Loops
- Writing with Loops
- Using For/In Loops
- Using Do/While Loops
- Checking if Java Is Enabled
- Functions
- Using Multi-level Conditionals
- Working with Functions That Return Values
- Handling Errors
- Putting More than One Script on a Page
- Scrolling Status Bars
- Status Bar Messages
Working with Functions That Return Values
(Netscape and Internet Explorer/Mac)
Up to this point, all the functions that we've seen simply do something and then return. Sometimes, though, we want to return a result of some kind. Script 3.9 (based on Script 3.2) checks on the fly to see whether or not the user has QuickTime enabled, instead of initializing a variable when the page first loads.

Script 3.9 A function can return a value, which can then be checked.
To return a value from a function:
-
function hasQT() { for (i=0; i<navigator.plugins.
The hasQT() function isn't passed any parameters, but it returns a value of true or false, depending on whether the user has the QuickTime plug-in installed. In this section, we return a value of true if at any point in the loop we find the QuickTime plug-in. Note that if a user has, for example, ten plug-ins, if QuickTime is the second one found, plug-ins 3-10 will never be checked. This can really help to speed up your code.length; i++) { if (navigator.plugins[i].name.
indexOf("QuickTime") >= 0) { return true } }
-
return false }
If we've looped through every plug-in and never found QuickTime, we return false, signifying that QuickTime is not installed. -
if (hasQT()) {
Here's where we use the function. Instead of checking an already set variable, we check on the fly to see if it's installed at this point. If it is, we see our movie, shown in
Figure 3.13
.
Figure 3.13 The QuickTime plug-in was found, so the script shows the movie.