Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-15-2009, 07:04 AM   PM User | #1
cshumate
New to the CF scene

 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
cshumate is an unknown quantity at this point
Smile How to Detect A Browser

I want to set up my website so it is compatible with all browsers and older versions of IE. So far in order to detect browsers and which version, I have this snippet of code...

<script type="text/javascript">
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
</script>

Ultimately what I want it to do is detect which browser is loading the page and after it determines which browser it will call up the appropriate CSS file to make sure it looks right in the browser.

In other words the code would say...

if the browser is Firefox, then load this css file
if the browser is IE but the version is less than 7, then load this cascading style sheet.

I just don't know how to code this appropriately,

Thanks!
cshumate is offline   Reply With Quote
Old 07-15-2009, 07:16 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
http://www.javascriptkit.com/javatut...jdetect3.shtml


Code:
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="IEspecific.css" />
<![endif]-->

<!--[if !IE]>
<link rel="stylesheet" type="text/css" href="allbutIE.css" />
<![endif]-->
What about IE7+?

It is your responsibility to die() if necessary….. - PHP Manual

Last edited by Philip M; 07-15-2009 at 08:22 AM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
browser detection, detect browser, javascript

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:26 PM.


Advertisement
Log in to turn off these ads.