AlfieWebDevTips Homefor new and experienced developers
[Home Home] [Web Development Web Development ] [Code Generators Code Generators ] [Resources Resources ] [Contact Us Contact ] |WebDevTips Privacy Privacy |
Print This Page

You are here : Home - Resources - FAQ - CSS Q4

FAQ - CSS Q4



Q4:How can I load a different style sheet for Netscape 4x?

A:There are several ways this can be achieved.
You can do it server side, if the server has asp, jsp, php or ssi enabled. The solutions to all those server side options would be specific to each language used - so we will look at a client side solution using javascript.

First create a generic style sheet, basic styles colors and fonts etc - so the content is readable (even if it doesn't have the bells and whistles of your main style)

Create your style sheet for Netscape 4x. Then create your full blown bells and whistles style.

If we go through the code below, here's what happens

  • Using html syntax we load the basic generic style sheet - so at least we know fonts and colors etc are fine no matter what happens next
  • Then we use javascript to detect the browser
  • Nothing complicated here - no need for extensive detection. Netscape 4x is the only browser that uses the document.layers object
  • If document.layers returns true then the netscape style sheet will be loaded.
  • If document.layers returns false we load the main style sheet.
  • If javascript is disabled or isn't available then the generic style will be the one that is used

<html> 
<head> 
    <title>Title</title> 
 
<link rel="stylesheet" href="path_to/GENERIC_STYLE.css"> 
 
  <script type="text/javascript" language="JavaScript"> 
<!--
    if(document.layers){document.write('<link rel="stylesheet" href="path_to/NETSCAPE_STYLE.css">');} 
    else 
    {document.write('<link rel="stylesheet" href="path_to/MAIN_STYLE.css">');} 
// -->
  </script> 
</head> 

<body> 
</body> 
</html>

The code above can be modified so that with full detection you can load a different style for mac, linux pc, Opera , Mozilla, IE, Netscape etc. How many different styles you need is up to you. Now you know how you can do it.




back to faq




Google
 

[back to top of page]   

[labelled with icra -  - this link will open in a new window] [RSS Content]

[Copyright © WebDevTips]