dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Web
Expertise: Intermediate
Dec 15, 1998

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


What's Beyond Browser Detection

Ever since browsers started multiplying, Web designers have wanted to take advantage of new capabilities without breaking the page for users of older browsers. To use image rollover effects safely, the HTML code has to be conditionalized for different browser capabilities. So developers have been coming up with ever more sophisticated browser-detection scripts. For example:
 
var browserlevel = -1;

function getlevel() {
if (browserlevel != -1) return browserlevel;
    if(navigator.appName.indexOf("Netscape") != -1 || navigator.appName.indexOf("Mozilla") != -1){
        if (navigator.userAgent.indexOf("Mozilla/2.0") != -1) 
            browserlevel = 2;
        else
            if (navigator.userAgent.indexOf("Mozilla/3.0") != -1) 
                browserlevel = 3;
        else
                if (navigator.userAgent.indexOf("Mozilla/4.") != -1)
                    browserlevel = 4;
                else
                    if (navigator.userAgent.indexOf("Mozilla/5.") != -1)
                        browserlevel = 5;
                    else
                        browserlevel = 1;
        }  else {  
                if (navigator.appName.indexOf("Internet Explorer") != -1){
                     if (navigator.userAgent.indexOf("Mozilla/4.") != -1) 
                     		browserlevel = 4; 
                         else	
                            browserlevel = 1;
                     } else 
                     	browserlevel = 1;
               }
return browserlevel;
}
The problems with this script are that it breaks all too easily with a fork in the road as happened with the release of Mozilla source code. A simpler and more robust approach is to use the Document Object Model (DOM) to test for a certain feature. For instance, a one line JavaScript can test if a browser can handle image rollovers:
 
if (document.images) {
	// code here for browser supporting rollover image effects
}
Erik Goetze
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date