|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am looking for some JavaScript that can determine what type of computer a person is browsing from and dynamically assign a stylesheet based on that. After doing a search, I found some code and tested it but I can't make it work! The original example used " alert('This is a Mac') " which works fine, but when I tried to switch it with some " document.write " the page goes blank after loading. My test code is below. Any help would be GREATLY appreciated!! :-) Thanks.
-Andy <html> <head> <script language="JavaScript"> <!-- function sniffer() { var isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false; if(isMac) { document.write('<link rel="stylesheet" href="mac.ccs" type="text/css">') } else { document.write('<link rel="stylesheet" href="pc.ccs" type="text/css">') } } //--> </script> </head> <body onLoad="sniffer()" class="bg"> <p class="text">This is a test</p> </body> </html> FYI, the "mac.css" contains the following: .bg { BACKGROUND-COLOR: #eedd82; } .text { FONT-FAMILY: Verdana, Helvetica, Arial, sans-serif; FONT-SIZE: 36px ; font-weight: bold; } |
|
#2
|
|||
|
|||
|
Sorry, just noticed that I misspelled ".ccs" After correcting it to ".css" it still doesn't work...
|
|
#3
|
||||
|
||||
|
you're calling the function in onload which is too late to write a link to a style sheet.. try it like this:-
Code:
<html>
<head>
<script language="JavaScript">
<!--
var isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
if(isMac) {
document.write('<link href="mac.css" rel="stylesheet" type="text/css">')
}
else {
document.write('<link rel="stylesheet" href="pc.css" type="text/css">')
}
// -->
</script>
</head>
<body>
<p>This is a test</p>
</body>
</html>
|
|
#4
|
|||
|
|||
|
Many thanks Jonathon!
-Andy |
![]() |
| Viewing: Dev Shed Forums > Web Design > CSS Help > Platform sniffer and CSS |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|