OpenLayers OpenLayers

Ticket #755: browserdetection.patch

File browserdetection.patch, 1.2 kB (added by euzuro, 1 year ago)

using the navigator.userAgent string, we make a generic function to return the name of the browser in a 2-letter code (as explained in the comment)

  • lib/OpenLayers/Util.js

    old new  
    965965    } 
    966966    return head; 
    967967}; 
     968 
     969 
     970/** 
     971 * @returns A two-character string which specifies which is the current  
     972 *           browser in which we are running.  
     973 *  
     974 *          Currently-supported browser detection and codes: 
     975 *           OP = Opera 
     976 *           IE = Internet Explorer 
     977 *           SF = Safari 
     978 *           FF = FireFox 
     979 *           MZ = Mozilla 
     980 *  
     981 *           If we are unable to property identify the browser, we return null. 
     982 * @type String 
     983 */ 
     984OpenLayers.Util.getBrowserName = function() { 
     985    var browserName = null; 
     986     
     987    var ua = navigator.userAgent.toLowerCase(); 
     988    if ( ua.indexOf( "opera" ) != -1 ) { 
     989        browserName = "OP"; 
     990    } else if ( ua.indexOf( "msie" ) != -1 ) { 
     991        browserName = "IE"; 
     992    } else if ( ua.indexOf( "safari" ) != -1 ) { 
     993        browserName = "SF"; 
     994    } else if ( ua.indexOf( "mozilla" ) != -1 ) { 
     995        if ( ua.indexOf( "firefox" ) != -1 ) { 
     996            browserName = "FF"; 
     997        } else { 
     998            browserName = "MZ"; 
     999        } 
     1000    } 
     1001     
     1002    return browserName; 
     1003};