# JS browser detection

**URL:** <https://forum.kirupa.com/t/js-browser-detection/173717>\
**Category:** web dev\
**Created:** [December 28, 2005, 10:56pm UTC](https://forum.kirupa.com/t/js-browser-detection/173717 "2005-12-28T22:56:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bird\_E](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Bird\_E](https://forum.kirupa.com/u/Bird_E)\
**Post date:** [December 28, 2005, 10:56pm UTC](https://forum.kirupa.com/t/js-browser-detection/173717/1 "2005-12-28T22:56:22Z")

</div>

Just wondering if it was possible to load different CSS stylesheets (using javascript) depending on the user’s browser.

I currently have:

> \<script type=“text/javascript”\>  
> function detectBrowser()  
> {  
> var browser=navigator.appName  
> if(browser==“Microsoft Internet Explorer”)  
> {\<link rel=“stylesheet” type=“text/css” href=“IE.css” /\>}  
> if(browser==“Mozilla Firefox”)  
> {\<link rel=“stylesheet” type=“text/css” href=“firefox.css” /\>}  
> else  
> {\<link rel=“stylesheet” type=“text/css” href=“uniform.css” /\>}  
> }  
> \</script\>

in the head section.

if it _is_ possible, am I going about it right? I have set a different coloured background for each css file, so I can tell them apart. Currently, I cant see any of the background colours i’ve specified, so I assume that it didnt load. What am I doing wrong?

Edit:

as an alternative, ive changed the script a bit-

> \<script type=“text/javascript”\>  
> function detectBrowser()  
> {  
> var browser=navigator.appName  
> if(browser==“Microsoft Internet Explorer”)  
> {\<link rel=“stylesheet” type=“text/css” href=“new.css” /\>}  
> else  
> {\<link rel=“stylesheet” type=“text/css” href=“firefox.css” /\>}  
> }  
> \</script\>

I want it to run a html line, but I dunno if its possible.

Heh, be nice because I’m still trying to learn.  
Thanks!
