OpenLayers OpenLayers

Changeset 3322

Show
Ignore:
Timestamp:
06/12/07 13:42:11 (1 year ago)
Author:
crschmidt
Message:

Apply browser detection patch which will allow us to determine browser name
with a single line, which is useful for the places in the code where we care
about what browser we're dealing with.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/example.html

    r1582 r3322  
    1010    <script src="../lib/OpenLayers.js"></script> 
    1111    <script type="text/javascript"> 
     12 
     13         
    1214        <!-- 
    1315        function init(){ 
     16 
     17            //set title name to include Browser Detection 
     18            // this is the only way to test the functionality  
     19            // of the getBrowserName() function 
     20            // 
     21            var header = OpenLayers.Util.getElement("browserHeader"); 
     22            header.innerHTML = "(browser: "; 
     23            var browserCode = OpenLayers.Util.getBrowserName(); 
     24            switch (browserCode) { 
     25                case "opera": 
     26                    browserName = "Opera"; 
     27                    break; 
     28                case "msie": 
     29                    browserName = "Internet Explorer"; 
     30                    break; 
     31                case "safari": 
     32                    browserName = "Safari"; 
     33                    break; 
     34                case "firefox": 
     35                    browserName = "FireFox"; 
     36                    break; 
     37                case "mozilla": 
     38                    browserName = "Mozilla"; 
     39                    break; 
     40                default:  
     41                    browserName = "detection error" 
     42                    break; 
     43            }                         
     44            header.innerHTML += browserName + ")"; 
     45 
    1446            var map = new OpenLayers.Map('map'); 
    1547 
     
    4678  </head> 
    4779  <body onload="init()"> 
    48     <h1>OpenLayers Example</h1> 
     80    <table><tr><td> 
     81        <h1>OpenLayers Example</h1> 
     82    </td><td> 
     83        <h3 id="browserHeader"></h3> 
     84    </td></tr></table> 
    4985    <div id="map"></div> 
    5086  </body> 
  • trunk/openlayers/lib/OpenLayers/Util.js

    r3317 r3322  
    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 *           * 'opera' -- Opera 
     976 *           * 'msie'  -- Internet Explorer 
     977 *           * 'safari' -- Safari 
     978 *           * 'firefox' -- FireFox 
     979 *           * 'mozilla' -- Mozilla 
     980 *  
     981 *          If we are unable to property identify the browser, we  
     982 *           return an empty string. 
     983 *  
     984 * @type String 
     985 */ 
     986OpenLayers.Util.getBrowserName = function() { 
     987    var browserName = ""; 
     988     
     989    var ua = navigator.userAgent.toLowerCase(); 
     990    if ( ua.indexOf( "opera" ) != -1 ) { 
     991        browserName = "opera"; 
     992    } else if ( ua.indexOf( "msie" ) != -1 ) { 
     993        browserName = "msie"; 
     994    } else if ( ua.indexOf( "safari" ) != -1 ) { 
     995        browserName = "safari"; 
     996    } else if ( ua.indexOf( "mozilla" ) != -1 ) { 
     997        if ( ua.indexOf( "firefox" ) != -1 ) { 
     998            browserName = "firefox"; 
     999        } else { 
     1000            browserName = "mozilla"; 
     1001        } 
     1002    } 
     1003     
     1004    return browserName; 
     1005};