[Contents] [Prev page] [Next page] [Last page]

Conditional Comments and the <NOLAYER> Tag

If an HTML file that contains layers is displayed in a browser that does not support layers, the contents are displayed, but not in a layer, since the <LAYER> and <ILAYER> tags are ignored. If the file contains any scripts that requires layers functionality, they will generate JavaScript errors if loaded into a browser that does not support layers.

To provide alternative content for such legacy browsers, you can use the <NOLAYER> and </NOLAYER> tags to surround content that is ignored by browsers that support layers.

To prevent older browsers from trying to display layers, you can use conditional comments. (Note: conditional comments are not supported in preview release 4..)

The syntax for conditional comments is:

<--&{"&"};{test expression};
layer related content
->

If the test expression returns true, the browser will evaluate the content in the comment. If the test expression returns false, the comment is treated as a comment and thus ignored. Older browsers that do not support conditional comments will always ignore the contents of the comment.

You can define the test expression to test whether layers are supported, for example by checking if the type of the document.layers object is object. (If layers are not supported, there will be no document.layers object.)

The following example displays a layer in a browser that supports layers, and displays the message "If only you had a browser that supports layers, you could see a lovely layer" in a browser that does not support layers.

<--&{typeof document.layers == "object"} 
<LAYER NAME="lovely" LEFT=10 WIDTH=300 HEIGHT=200
 BGCOLOR="blue">
  <H1>Oh how lovely is my layer</H1>
  <IMG SRC="lovely.gif">
</LAYER> 
-->
<NOLAYER>
  <P>If only you had a browser that supports layers, you could see a 
lovely layer.</P>
</NOLAYER>


[Contents] [Prev page] [Next page] [Last page]

Copyright © 1997, Netscape Communications. All rights reserved.