Click to See Complete Forum and Search --> : browser detect for differering css


ritmoritmo
10-07-2003, 11:35 AM
i have a site where i need seperate stylesheets (more than one) for each platform/browser etc.

i have the following code but need to ammend to cater for more .css file. eg ie/1.css, ie/2.css and ie/3.css. how do i do this with the document.write command?

any pointers? code examples? thanks in advance

<script type="text/javascript">
<!-- hide javascript from all non-enabled browsers.
if (parseInt(navigator.appVersion) >= 4) {
var IE4 = (navigator.appVersion.indexOf("MSIE") > 0);
var NN4 = (navigator.appName == "Netscape");
var OS;
if (navigator.appVersion.indexOf("Win") > 0) OS = "Windows";
if (navigator.appVersion.indexOf("Mac") > 0) {OS = "MacOS";}

switch (OS) {

case "Windows":

if (IE4 > 0)
document.write ("<LINK href=ie/nn.css' rel='stylesheet' type='text/css'");

if (NN4 > 0)
document.write ("<LINK href='net/eng/nn.css' rel='stylesheet' type='text/css'");
break;

case "MacOS":
if (IE4 > 0)
document.write ("<LINK href='eng/iemac.css' rel='stylesheet' type='text/css'");

if (NN4 > 0)
document.write ("<LINK href='eng/nnmac.css' rel='stylesheet' type='text/css'");
break;
}
}
//-->
</script>

pyro
10-07-2003, 11:36 AM
What happens for the 13% of users who do not have JavaScript enabled?

Robert Wellock
10-07-2003, 11:55 AM
You use a server-side solution, like PHP :D

ritmoritmo
10-07-2003, 11:55 AM
they get ignored!
my clients requirements!

thanks for response, but any positive suggestions out there?

Robert Wellock
10-07-2003, 12:01 PM
If you must use JavaScript just add more document.write(..xyz..); lines for the additional sheets if the user has no JavaScript enabled and get ignored they get no CSS at all, is that really a solution you would like?

ritmoritmo
10-07-2003, 12:09 PM
dude, i get paid for delivering what i'm asked for.

not uncommon for clients to ask for inapropriate solutions. i have advised to all the pitfalls.

is there a better solution? how would you do it?

thanks

pyro
10-07-2003, 12:10 PM
Originally posted by Robert Wellock
You use a server-side solution, like PHP :D

ritmoritmo
10-07-2003, 12:16 PM
thanks for all the advice on php.

unfortunately i don't have this option as i'm restricted to the servers my client uses and have to stick to strict xhtml dtd.

any javasript sugestions anyone?

Vladdy
10-07-2003, 12:56 PM
Simplify your layout so it looks decent in major graphical browsers with a single style sheet. For older browsers such as NN4.* - hide stylesheet using @import rule. You can also overcome IE bugs by using descendant selectors (which IE does not understand)

ritmoritmo
10-07-2003, 01:06 PM
thanks Vladdy

nkaisare
10-07-2003, 01:14 PM
Originally posted by ritmoritmo
they get ignored!
my clients requirements!
So the client told you "Use Javascript, I won't pay you if you don't"? I am not trying to be difficult here. Just that you must have taken lots of pains to design XHTML strict page. Why not go some distance more and give a better solution than above.

The following link has amazing amount of resources for your need.
http://css-discuss.incutio.com/?page=BrowserDetection
Especially read the section on CSS hacks. If javascript is best suited, so be it. But let that be your decision, not something thrust down your throat.

ritmoritmo
10-07-2003, 01:27 PM
nkaisare, you may be in a lucky position to dictate all this to your client and turn work down. i'm not.

this is for a government website with way too many standards for me to be interested in questioning.

i'm being paid for specific taks to a site that already exists. if i don't do it, someone else will.

i totally get your point and know you're not being picky. its just a small project with a little javascript help needed. will check the link you gave me. thanks

Vladdy
10-07-2003, 02:18 PM
One of the standards government site should comply with is accessiblity regulation. According to these regulation a site should not rely on javascript. It's a valid argument that users with javascript disabled will get unformated content and therefore there is no impact on accessibility in your particular case. On the same token why resort to javascript and limit user experience when browser support issues can be solved by other means.

Besides the old browsers NN4 and IE4 the major problem with CSS layouts is poor IE support of CSS2. The easiest solution is to declare a default stylesheet for your document and then use IE conditional comment to add another IE specific stylesheet that redefines those selectors you are having trouble with.

spufi
10-07-2003, 03:52 PM
If the site's webhost doesn't support PHP, what server side language does it support?

ritmoritmo
10-08-2003, 03:45 AM
as i'm not able to use any server side scripting.
i'm just developing dhtml templates (no tables) to be converted and parsed as xml files.