Team LiB
Previous Section Next Section

Chapter 10: Handling Web Browser, Screen Resolution, and Color Depth Differences

As anyone in the technology field knows, much difference exists between products made by different companies—even when the products are supposed to perform the same function. A perfect example of this phenomenon is the differences between Internet Explorer and Netscape. A page written and tested for Internet Explorer may look nothing like it should in Netscape and vice versa. Only a small range of features is implemented identically by both of these browsers. But that's not the only problem you have to deal with when designing a Web page. Not only are the browsers themselves fundamentally different, but they also have several different versions, which each behave in a different manner. If you add in the fact that the underlying operating system can have one of several resolutions and color depths that affect the way a Web page is displayed, you may be tempted to give up the idea of ever creating a professional-looking and effective Web site. But don't give up yet—this chapter will show you how to avoid the pitfalls and traps that occur along the path of creating a multi-browser, multi-platform Web page.

Hiding Scripts from Older Browsers

Hiding the JavaScript from browsers that do not support it is one of the most fundamental steps in creating a JavaScript-enabled Web page that can run under all conditions. Netscape Version 1 and Internet Explorer Versions 1 and 2 do not support JavaScript-enabled Web pages, and they'll behave strangely when they encounter your JavaScript. To prevent this strange behavior, you can enclose your scripts in HTML comment tags. This technique has been used throughout this book and takes the following form:

<script language="JavaScript">
<!--
  <JavaScript statements>
// -->
</script>

Enclosing your scripts in HTML comment tags will prevent the non-JavaScript-enabled browsers from trying to interpret the JavaScript statements as HTML. The closing HTML comment line follows a JavaScript style comment so that the JavaScript interpreter will not try to interpret the comment as a statement.

The HTML <NOSCRIPT> tag is also useful in the event that the user's browser does not support your scripts. Inside the <NOSCRIPT> tag you can place a suitable HTML message that will only be displayed if the browser does not support the script or if the user has disabled the browser's script functionality.

Following is an example of using the <NOSCRIPT> tag:

<html>

  <head>
    <title>
      JavaScript Professional Projects - Hiding Scripts from
                                               Older Browsers
    </title>
  </head>

  <body>

    <center>
       <font size=6>JavaScript Professional Projects</font><br>
       <font size=4>Chapter 10: Hiding Scripts from
                                        Older Browsers</font>

    </center>
  
    <br><br> 
    <br><br>

    <script language="JavaScript"> 
    <!--
      document.write( "Congratulations, your browser" +
                            "supports JavaScript!" ); 
    // -->
    </script>
    <noscript>
      I'm sorry, your browser does not support my scripts.<br>
      Please download a newer browser or
      enable scripts for your browser.
    </noscript>

  </body>

</html>

The <NOSCRIPT> tags do not need to follow the <SCRIPT> tags—they can be placed anywhere within the body of the page. It is a good idea to always use <NOSCRIPT> tags when you are writing JavaScript-enabled pages, so that the user will be aware of any problems that might occur with his or her browser.


Team LiB
Previous Section Next Section