There is a very easy way to distinguish between IE and everything else:
Code:
<style type="text/css">
body {
background-image: url(allelse.gif);
}
</style>
<!--[if IE]>
<style type="text/css">
body {
background-image: url(ie.gif);
}
</style>
<![endif]-->
No javascript required. For the rest of them we have the navigator object and its various properties, as well as various quirks that can be detected. These all (as far as I know) require javascript and many can be spoofed, but generally aren't, and I suppose that even if they were, it wouldn't be that big of a deal for something as innocent as this. See:
http://www.dynamicdrive.com/dynamici...sersniffer.htm
Also check this on Google:
http://www.google.com/search?client=...utf-8&oe=utf-8
Here's one way to detect several popular browsers while setting a background image for each:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
background-image: url(allelse.gif); /* image for all those not detected */
}
</style>
<!--[if IE]>
<style type="text/css">
body {
background-image: url(ie.gif); /* IE image */
}
</style>
<![endif]-->
<script type="text/javascript">
(function(){
var browser = '';
if(/Google/i.test(navigator.vendor)){
browser = 'chrome.gif'; //Chrome image
}
else if(/Apple/i.test(navigator.vendor)){
browser = 'safari.gif'; //Safari image
}
else if(window.opera){
browser = 'opera.gif'; //Opera image
}
else if(typeof document.documentElement.style.MozBinding === 'string'){
browser = 'mozilla.gif' //Firefox and other Mozilla based browsers image
}
if(browser !== ''){
document.write('<style type="text/css">body { background-image: url(' + browser + '); } <\/style>');
}
})();
</script>
</head>
<body>
</body>
</html>
Bookmarks