Set a variable to determine what version of JavaScript we support
/*
Examples From
JavaScript: The Definitive Guide, Fourth Edition
Legal matters: these files were created by David Flanagan, and are
Copyright (c) 2001 by David Flanagan. You may use, study, modify, and
distribute them for any purpose. Please note that these examples are
provided "as-is" and come with no warranty of any kind.
David Flanagan
*/
<html>
<!-- Set a variable to determine what version of JavaScript we support. -->
<!-- This technique can be extended to any number of language versions. -->
<script language="JavaScript"> var _version = 1.0; </script>
<script language="JavaScript1.1"> _version = 1.1; </script>
<script language="JavaScript1.2"> _version = 1.2; </script>
<!-- Run this code on any JavaScript-enabled browser. -->
<!-- If the version is not high enough, display a message. -->
<body>
<script language="JavaScript">
if (_version < 1.1) {
document.write('<hr><h1>This Page Requires JavaScript 1.1</h1>');
document.write('Your JavaScript 1.0 browser cannot run this page.<hr>');
}
</script>
</body>
<!-- Now run the actual program only on JavaScript 1.1 browsers. -->
<script language="JavaScript1.1">
// The actual JavaScript 1.1 code goes here.
</script>
</html>
Related examples in the same category