From 76f9234e3b99db96071cf459cb6bd710cc7d7cf1 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 12 Jun 2007 17:42:11 +0000 Subject: [PATCH] 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. git-svn-id: http://svn.openlayers.org/trunk/openlayers@3322 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/example.html | 38 +++++++++++++++++++++++++++++++++++++- lib/OpenLayers/Util.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/examples/example.html b/examples/example.html index a9c90f4cf6..6ce8529edd 100644 --- a/examples/example.html +++ b/examples/example.html @@ -9,8 +9,40 @@ -

OpenLayers Example

+
+

OpenLayers Example

+
+

+
diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index c57a990216..28487d1644 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -965,3 +965,41 @@ OpenLayers.Util.removeTail = function(url) { } return head; }; + + +/** + * @returns A two-character string which specifies which is the current + * browser in which we are running. + * + * Currently-supported browser detection and codes: + * * 'opera' -- Opera + * * 'msie' -- Internet Explorer + * * 'safari' -- Safari + * * 'firefox' -- FireFox + * * 'mozilla' -- Mozilla + * + * If we are unable to property identify the browser, we + * return an empty string. + * + * @type String + */ +OpenLayers.Util.getBrowserName = function() { + var browserName = ""; + + var ua = navigator.userAgent.toLowerCase(); + if ( ua.indexOf( "opera" ) != -1 ) { + browserName = "opera"; + } else if ( ua.indexOf( "msie" ) != -1 ) { + browserName = "msie"; + } else if ( ua.indexOf( "safari" ) != -1 ) { + browserName = "safari"; + } else if ( ua.indexOf( "mozilla" ) != -1 ) { + if ( ua.indexOf( "firefox" ) != -1 ) { + browserName = "firefox"; + } else { + browserName = "mozilla"; + } + } + + return browserName; +};