HTML Tutorial


 /help/HTML Help Forum   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Detecting Browser and Loading CSS
Post new topic   Reply to topic    HTML Help Forum -> Javascript
View previous topic :: View next topic  
Author Message
Maggical



Joined: 10 Jan 2005
Posts: 46
Location: Rosario - Argentina

PostPosted: Wed Jun 24, 2009 5:53 pm     Detecting Browser and Loading CSS Reply with quote

Hi there, I've been using a javascript for a long time now, that loads a different css if the user has Internet Explorer 6...

The thing is that I now want to load different things in many other cases, I would need:

- Internet Explorer 6 or below
- Internet Explorer 7 or above
- Firefox
- Safari

Any idea on how to tweak my code to make it work?

Here it is:

Code:
<script type="text/javascript">
// Function to include the css
function includeCSS(src) {
   document.write('<link rel="stylesheet" type="text/css" href="'+src+'">');
}

// Detection begins
version=0;

if(navigator.appVersion.indexOf("MSIE")!=-1){
   temp=navigator.appVersion.split("MSIE");
   version=parseFloat(temp[1]);
}

//If it's not IE it returns 0
if((version>=6.0) && (version<7.0)){
   // Case IE6
   includeCSS("css/leftIE6.css");
}
else{
   // All the other cases
   includeCSS("css/left.css");
}
</script>


And here's some info that I can't work around to make it work:

http://www.javascriptkit.com/javatutors/navigator.shtml

Thanks a lot,

Javier
Maggical



Joined: 10 Jan 2005
Posts: 46
Location: Rosario - Argentina

PostPosted: Wed Jun 24, 2009 6:09 pm     Reply with quote

For those of you who have the same problem, here's a workaround using jQuery:

http://agachi.name/weblog/archives/2006/07/22/avoiding-css-hacks-using-javascript.htm

Good luck!
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum -> Javascript All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial