HTML and CSS Reference
In-Depth Information
Figure 10.8 Browser properties (Example 10.2).
complete JavaScript program ready to copy and paste into your editor. Save it as a .js file
and then include it in your JavaScript code as shown in Example 10.3. The script creates
a literal JavaScript object called BrowserDetect and defines a number of methods to
detect your browser's name, version, and operating system. The code is fully explained
by the author. At this point in your JavaScript experience, you should be able to read the
script and understand the explanations provided.
To display the results, the following function was added to the list of methods pro-
vided by the original script:
printResults: function display(){
document.write("<b>This browser is "+BrowserDetect.browser);
document.write( " version "+ BrowserDetect.version + ".<br />");
document.write("The Operating System is "+ BrowserDetect.OS +
"</b>.<br />");
1 <script type="text/javascript" src="browser_sniffer_real.js">
<script type="text/javascript">
BrowserDetect.init() ;
BrowserDetect.printResults() ;
The source file is a .js file, downloaded from .
The init() method for the BrowserDetect object sets the properties: browser , version
and OS for the browser you are using to view the output.
Search WWH ::

Custom Search