CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 22nd, 2001, 07:23 PM
andyf andyf is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: San Francisco
Posts: 6 andyf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Platform sniffer and CSS

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; }

Reply With Quote
  #2  
Old June 22nd, 2001, 07:28 PM
andyf andyf is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: San Francisco
Posts: 6 andyf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking OOPs

Sorry, just noticed that I misspelled ".ccs" After correcting it to ".css" it still doesn't work...

Reply With Quote
  #3  
Old June 22nd, 2001, 07:53 PM
Jonathon's Avatar
Jonathon Jonathon is offline
T-Shirt Tragic
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2001
Location: Melbourne, Australia
Posts: 838 Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 10 h 53 m 11 sec
Reputation Power: 215
Send a message via Skype to Jonathon
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>

Reply With Quote
  #4  
Old June 23rd, 2001, 07:23 PM
andyf andyf is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: San Francisco
Posts: 6 andyf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Many thanks Jonathon!

-Andy

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > Platform sniffer and CSS


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway