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 />");
}
EXAMPLE 10.3
1 <script type="text/javascript" src="browser_sniffer_real.js">
</script>
<script type="text/javascript">
2
BrowserDetect.init() ;
3
BrowserDetect.printResults() ;
</script>
EXPLANATION
1
The source file is a .js file, downloaded from http://www.quirksmode.org/js/detect.html .
2
The init() method for the BrowserDetect object sets the properties: browser , version
and OS for the browser you are using to view the output.
Continues
 
Search WWH ::




Custom Search