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=http://www.webdeveloper.com/forum/archive/index.php/ie/nn.css' rel='stylesheet' type='text/css'");
if (NN4 > 0)
document.write ("<LINK href='http://www.webdeveloper.com/forum/archive/index.php/net/eng/nn.css' rel='stylesheet' type='text/css'");
break;
case "MacOS":
if (IE4 > 0)
document.write ("<LINK href='http://www.webdeveloper.com/forum/archive/index.php/eng/iemac.css' rel='stylesheet' type='text/css'");
if (NN4 > 0)
document.write ("<LINK href='http://www.webdeveloper.com/forum/archive/index.php/eng/nnmac.css' rel='stylesheet' type='text/css'");
break;
}
}
//-->
</script>What happens for the 13% of users who do not have JavaScript enabled?You use a server-side solution, like PHP they get ignored!
my clients requirements!
thanks for response, but any positive suggestions out there?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?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?
thanksOriginally posted by Robert Wellock
You use a server-side solution, like PHP 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?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)thanks VladdyOriginally 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.
<!-- m --><a class="postlink" href="http://css-discuss.incutio.com/?page=BrowserDetection">http://css-discuss.incutio.com/?page=BrowserDetection</a><!-- m -->
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.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. thanksOne 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.If the site's webhost doesn't support PHP, what server side language does it support?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.
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=http://www.webdeveloper.com/forum/archive/index.php/ie/nn.css' rel='stylesheet' type='text/css'");
if (NN4 > 0)
document.write ("<LINK href='http://www.webdeveloper.com/forum/archive/index.php/net/eng/nn.css' rel='stylesheet' type='text/css'");
break;
case "MacOS":
if (IE4 > 0)
document.write ("<LINK href='http://www.webdeveloper.com/forum/archive/index.php/eng/iemac.css' rel='stylesheet' type='text/css'");
if (NN4 > 0)
document.write ("<LINK href='http://www.webdeveloper.com/forum/archive/index.php/eng/nnmac.css' rel='stylesheet' type='text/css'");
break;
}
}
//-->
</script>What happens for the 13% of users who do not have JavaScript enabled?You use a server-side solution, like PHP they get ignored!
my clients requirements!
thanks for response, but any positive suggestions out there?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?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?
thanksOriginally posted by Robert Wellock
You use a server-side solution, like PHP 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?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)thanks VladdyOriginally 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.
<!-- m --><a class="postlink" href="http://css-discuss.incutio.com/?page=BrowserDetection">http://css-discuss.incutio.com/?page=BrowserDetection</a><!-- m -->
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.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. thanksOne 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.If the site's webhost doesn't support PHP, what server side language does it support?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.