Полезная информация

JavaScript: The Definitive Guide

Previous Chapter 18
Compatibility Techniques

18.4 Compatibility Through CGI Scripts

When your web application includes the use of CGI scripts, another approach to all forms of JavaScript compatibility is to use a CGI script on your web server to generate all the JavaScript code used in your application. Then, this script can inspect the User-Agent field of the HTTP request header. This allows it to determine exactly what browser the user is running and generate customized JavaScript code that is known to work correctly on that browser. And if the CGI script detects that the user's browser does not support JavaScript, it can generate web pages that do not require JavaScript at all. The only drawback to this approach is that the CGI script cannot detect when a user has disabled JavaScript support in their browser.

Using a CGI script is also an ideal way to handle the SRC attribute of the <SCRIPT> tag. If the CGI script detects a browser that supports this attribute, it can trivially generate a web page that simply contains a reference to its JavaScript code. For other browsers, it can include that JavaScript code literally into the web page.

The Navigator.userAgent property contains the string that a browser sends as its User-Agent HTTP header. See the reference page for this property for more information. Note that writing CGI scripts is well beyond the scope of this book. For more information on doing so, see CGI Programming on the World Wide Web by Shishir Gundavaram, published by O'Reilly & Associates.

Previous Home Next
Compatibility with JavaScript 1.0 Browsers Book Index LiveConnect: JavaScript and Java

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell