Tutorials Bugs Masterclass Free stuff Test pages Proposals

Browser detection

Here's RichInStyle.com's free browser detection script that detects between IE 3 and 3.01:

ua=navigator.userAgent;
l='<LINK rel="stylesheet" type="text/css" href="ie3';
if (ua.indexOf('IE 3.0')!=-1){
    if (((ua.indexOf('IE 3.0A')!=-1) || (ua.indexOf('IE 3.0 ')!=-1)) && (ua.indexOf('Mac')==-1)) document.write(l+'0.css">');
    else document.write(l+'.css">');
}

Here's RichInStyle.com's browser detection script that detects between newer browsers:

/* (c) 2000 RichInStyle.com (www.richinstyle.com); you may only use this script in the SCRIPT element of a page. You must not alter or remove this message */
ua=navigator.userAgent;
l='<LINK rel="stylesheet" type="text/css" href="';
c='.css">';
if (ua.indexOf('IE 4')!=-1)document.write(l+'ie4'+c);
if (ua.indexOf('IE 5')!=-1)document.write(l+'ie5'+c);
if (ua.indexOf("Opera 3")!=-1)document.write(l+'op3'+c);
else if (ua.indexOf("compatible")==-1) {
  if (ua.indexOf("/4")!=-1)document.write(l+'nn4'+c);
  if (ua.indexOf("/5")!=-1)document.write(l+'nn5'+c);
}

If you want to read more about how to use them, they are discussed in RichInStyle.com's guide to cross-browser style.