Mohammed Khader
Mohammed Khader

Reputation: 1

How can I detect the browser in JavaScript?

I need to detect the browser with JavaScript.

I have an image gallery with different js files for FireFox, Chrome, and IE. How can I detect the browser display the corresponding file?

Upvotes: 0

Views: 182

Answers (2)

Matt Ball
Matt Ball

Reputation: 360016

You could also use conditional comments in the HTML to grab entirely different script files:

<!--[if IE]> 
<script src="http://example.com/ie-specific.js"></script>
<![endif]-->
<!--[if !IE]> -->
<script src="http://example.com/real-browsers.js"></script>
<!-- <![endif]-->

Upvotes: 1

TJHeuvel
TJHeuvel

Reputation: 12618

If you are already using jquery you can use their API to detect the browser. Otherwise you can extract the users browser from the navigator.useragent property.

Upvotes: 3

Related Questions