Callum
Callum

Reputation: 77

Detecting if a user's browser is opera or isn't firefox 21

I am making a video player using HTML5 however not all browsers support the video format of MP4 and I late the skills or hardware to make something that coverts a video format to a different video format. So is there a way to detect if the user's browser is opera or isn't firefox 21?

Upvotes: 1

Views: 128

Answers (2)

sbugert
sbugert

Reputation: 345

You can use http://modernizr.com/ to detect browser features.

It will add classes to your html depending on the browser's features. Or in your Javascript it's as simple as:

if (Modernizr.video.h264 == "") {
    // h264 is not supported
}

You shouldn't rely on user agent sniffing because it is rather unreliable compared to feature detection.

Upvotes: 6

ggmathur
ggmathur

Reputation: 843

Yes. You can do this either server side or client side.

Every browser sends a UserAgent header. For example, Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/21.0.1 is the user agent for Firefox 21 running on Windows.

There are numerous libraries that can help you parse and identify the user agents. I believe this is supported in jQuery.

Upvotes: 0

Related Questions