Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 125 Time: 06:33 - Jun 14, 2007  

neerusaini

How to Identify the browser using java script (for IE/Safari/Firefox)

How to Identify the browser using java script (for IE/Safari/Firefox)

Answer Discussion
Tutorials

 

euzuro

Date:: Jun 14, 2007

Time:: 08:36

/**
* @returns A 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;
};

nidhi

Date:: Jun 14, 2007

Time:: 17:42

For info only, this is old skool, useful really only if you wanted to check for IE

Before it was possible to use appName, but both Mozilla and Safari both return Netscape which is why you cant really use it now.

the navigator object is a throwback from Netscape Navigator days I believe hence the use of that keyword.

simple test I used. This is for information only, it is not something you should be using. As I said before, only handy if you want to check for MSIE only.

<HTML>
<head>
<script language="javascript">
function tellmemybrowser() {
 alert(navigator.appName);
}
</script>
</head>

<BODY onload="tellmemybrowser();">
Yo
</BODY>
</HTML>


So your best bet to identify individual browsers nowadays is to use userAgent and which euzuro has given you the answer to your question.

You can use the navigator object to determine other things as well like version (use indexOf) and os. A sample function can be found here http://www.quirksmode.org/js/detect.html

xarcus

Date:: Jun 16, 2007

Time:: 05:45

MSIE, Opera, Konqueror, Safari, Netscape, Gecko based
Two versions simple and full featured

http://techpatterns.com/downloads/javasc...

admin

Date:: Aug 22, 2007

Time:: 13:25

neerusaini, did you get your question solved?

If you did then please close this question and distribute the points. If you found the solution on your own, we would be very happy if you could explain it here for the sake other users having the same problem.

If you didn't get a solution to your problem, please leave a comment here to let the experts know that you're still looking for an answer.

Thanks,
The Quomon Admin Team

shashi.programmer

Date:: Sep 27, 2007

Time:: 04:08

try to check this
http://www.mistered.us/tips/javascript/b...

Ramasamy.N

Date:: Oct 12, 2007

Time:: 05:59


navigator.appName

prashanth.guru

Date:: Oct 18, 2007

Time:: 06:15

http://www.javascriptkit.com/javatutors/...
The above link helps allot on your question.

Thanks,
Prash

mikkelnh

Date:: Mar 17, 2011

Time:: 10:38

nice browser and OS detect script here i use it myself and it works gr8
http://fatkid.dk/Article/Articel/9

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10279

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es