Java Reference
In-Depth Information
document.write(“Firefox is fully supported”);
}
else if (browserName == “Safari”)
{
document.write(“Safari is fully supported”);
}
else if (browserName == “Chrome”)
{
document.write(“Chrome is fully supported”);
}
else if (browserName == “Opera”)
{
document.write(“Opera is fully supported”);
}
else
{
document.write(“<h2>Sorry this browser version is not supported</h2>”);
}
On the fi nal part of the if statements is the else statement that covers all other browsers and tells the
user the browser is not supported.
Finally, there is an <noscript/> element for early browsers and for users who have chosen to disable
JavaScript. This displays a message informing the user their browser isn't JavaScript-enabled.
<noscript>
<h2>This website requires a browser supporting scripting</h2>
</noscript>
As mentioned earlier, although this script works fi ne at the moment, it's possible that browsers will
change their userAgent strings and you'll need to update the function to keep track of this. Also, some
browsers pretend to be other browsers even if they don't function 100 percent the same, which can leave
your code showing errors.
For these reasons, stick to the object checking method detailed earlier in the chapter.
Summary
You've covered a lot in this chapter, but now you have all the grounding you need to move on to more
useful things such as forms and user input and later to more advanced areas of text and date
manipulation.
You turned your attention to the browser, the environment in which JavaScript exists. Just as
JavaScript has native objects, so do web browsers. The objects within the web browser, and the
hierarchy they are organized in, are described by something called the Browser Object Model
(BOM). This is essentially a map of a browser's objects. Using it, you can navigate your way
around each of the objects made available by the browser, together with their properties, meth-
ods, and events.
Search WWH ::




Custom Search