Stylesheet Based on Browser..
Sunday, January 13, 2008Just a small piece of JavaScript that detects which of the main web browsers you are using (Firefox, Safari, Opera or Internet Explorer) and selects a stylesheet accordingly. It's fairly vague i.e. it doesn't take into account different versions/releases of these browsers, but if you want a quick fix so you can manage how your site looks in all the latest browsers, this is the one to use..
<script type="text/javascript">
//Below are the main browser appName strings..
//'Microsoft Internet Explorer' (all versions)
//'Netscape' (for Firefox)
//'Opera'
//'Mozilla'
var csshref
if(navigator.appName=='Netscape'){csshref='css/firefox.css'}
else if(navigator.appName=='Opera'){csshref='css/opera.css'}
else{csshref='css/normal.css'}
csslink = document.createElement('link')
csslink.rel='stylesheet'
csslink.href = csshref
document.getElementsByTagName('head')[0].appendChild(csslink)
</script>
Comments (0)