Forum Moderators: open

Message Too Old, No Replies

what if Javascript is disabled in browser?

how to get the browser to pick one style sheet if javascript is disabled?

         

still learning

9:17 am on Aug 17, 2005 (gmt 0)

10+ Year Member



hello,

In response to a post I sent yesterday, I was adviced to use no more than 2 style sheets for two kind of browsers. The rest should be done by css hacks. I'm going to try to do that.

However, what happens when a use doesn't have JavaScript enabled? How can I make it pick a style sheet?

here is my script at the moment:

-----------------------------------------------
<script language="JavaScript"><!--
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;

if (browser_type == "Microsoft Internet Explorer") {
document.write("<link REL='stylesheet' HREF='css/ie.css' TYPE='text/css'>");
}

else {
document.write("<link REL='stylesheet' HREF='css/other-browsers.css' TYPE='text/css'>");
}

// --></script>
------------------------------------------------

So if the browser doesn't allow JavaScript, it won't pick any of these style sheets.
If I attach the html page to the two style sheets then it always take the last one in the list.

I hope it makes sense.

Thanks a lot

outrun

10:22 am on Aug 17, 2005 (gmt 0)

10+ Year Member



Simpliest way is to comment out a line if javascript is enabled for example:

<script type="text/javascript">document.write("<!--");</script>
<link rel="stylesheet" type="text/css" href="/default.css" />
<script type="text/javascript">document.write("-->");</script>

still learning

10:41 am on Aug 17, 2005 (gmt 0)

10+ Year Member



great! thanks a lot.

bedlam

5:38 am on Aug 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simpliest way is to comment out a line if javascript is enabled for example:

No it's not :-)

The simplest way is to use the html element specifically created for the purpose [w3.org]:

<noscript>
<link rel="stylesheet" type="text/css" href="/default.css" />
</noscript>

-B

kaled

9:33 am on Aug 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately, <noscript> is not considered valid markup in the <head>. However, all browsers that I have have tested are fine with it.

Another case of idiots in charge of setting standards.

Of course, I can see no reason why <style> should be disallowed in the <body> either.... crazy!

Kaled.

bedlam

2:44 pm on Aug 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately, <noscript> is not considered valid markup in the <head>. However, all browsers that I have have tested are fine with it.

You're right Kaled - at least, now that you mention it, I recall noscript flunking validation when used in the head of a document. On the other hand, I looked around a bit and found it in use in the head on a valid page of mine. I have no idea why how I found this out, or why it's true, or if it's just a bug in the validator, but wrapping <noscript> elements in <object> elements causes the page to pass validation. On the other hand, <link ... /> inside <noscript> fails anyway so my solution is flawed at best...

;-)

-B

JAB Creations

8:33 pm on Aug 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is my solution...

Put your default stylesheet in the head anyway. Javascript always seems to over-ride default stylesheets when the script is in the head (sometimes even misplaced in the body). The other thing is the rule of thumb, if a class is defined with more attributes in one stylesheet then the other then it will use that stylesheet over the less defined.

When will we have both validation and support?

"256 EB of ram huh? When I was a kid we have 2gbs of ram and our operating systems would use the hard drive first anyway and thats how we lived back in the blizzard of 05!" "2gbs of cache grampa?"