How to get a name of browser by using JavaScript? [duplicate] - javascript

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Reliable browser detection with javascript?
How to get a name of browser by using JavaScript?
I expected to see only the name like this Firefox, Chrome, Safari etc.

If you're sure you need it: jQuery.browser. Promise you'll only use it as a last resort.

Take a look at jQuery.browser, but read the warning, it's better to detect features. What are you trying to achieve?

There is no way to confidently "get" only the name in a cross browser manner.
The best you can do is hack around with regular expressions on window.navigator.userAgent and hope future browsers don't break it.
But the userAgent is a mess. Don't touch it.
The W3C claims that
window . navigator . appName
Returns the name of the browser.
This is false as window.navigator.appName in chrome returns "NetScape"
The `Navigator object is very poorly implemented in browsers
Do not browser detect

Related

Capture Image from Webcam through js/JavaScript [duplicate]

This question already has answers here:
How can I capture an image via the user's webcam using getUserMedia?
(3 answers)
Closed 2 years ago.
I am looking to capture the image from the webcam.
I have tested quite a few libraries including
https://github.com/jhuckaby/webcamjs
https://github.com/amw/jpeg_camera
But all existing libraries are very old and no longer maintained by authors.
I have also tried "navigator.mediaDevices.getUserMedia" to capture the image but it does not work with safari.
I am wondering if you can suggest something that works cross-browsers and can manage a responsive view as well.
Thanks.
The navigator.mediaDevices.getUserMedia method should work with the latest version of safari 11. You'll want to use the MediaDevices.getUserMedia() method which has full support by almost every latest browser (except IE).
Note that if your writing an HTML file and opening it in the browser, it may not work because your browser may require a secure context (HTTPS instead of HTTP) to use that method.
See https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
Also, Sam Dutton created a great example, and you can find the github code for it as well.

How can I reliably detect the browser without using window.navigator?

I know there are a thousand questions on Stack Overflow about detecting the browser with JavaScript. My question is how can you detect the browser without window.navigator (which includes navigator.userAgent)?
First, to clarify, I don't need to know the rendering engine, this isn't for adaptive layout, and don't panic: I'm already doing feature detection. If why I'm asking about detecting the browser is important, please comment and I'll be happy to splice in the explanation, but it will probably make the question egregiously long.
Next, let me describe why my question is not a duplicate of:
Browser detection in Javascript? because of 19 answers, 12 of them use navigator.userAgent specifically (including jQuery.browser which used userAgent, and is now gone anyway), 4 use navigator.appName (which gives "Netscape" in Chrome...), 1 side-steps the question by recommending feature detection, which is different from browser detection (I am already using feature detection, but to know the extent to which I can use them, I need browser detection), and 2 aren't really answers or are IE-specific. (Although this non-answer is actually very explanatory about why my question here is relevant: I'm trying to avoid hitting pain points on certain browsers that would crash the tab!) Since my question is asking for an answer (even a hack?) without using window.navigator, it is not a duplicate of that question.
Check if the user is using IE because of 11 answers, 10 use navigator.userAgent and 1 of them uses an IE trick to detect IE only, which is not sufficient to answer my question (though it may be potentially be a small part of a helpful solution posted here)?
In Javascript, how do I determine if my current browser is Firefox on a computer vs everything else? because of 11 answers, 8 use navigator.userAgent, 2 recommend feature detection (again, not my question), and 1 isn't even an answer, really.
How to detect chrome and safari browser (webkit) because of 8 answers, 6 of them use navigator.userAgent, and 2 are webkit-specific. Unfortunately, WebKit is not necessarily tied to just Safari, and I need to know the browser, not the rendering engine.
Hopefully that is crystal clear.
I know there are other ways to do this, but I don't know the ins-and-outs of each browser well enough. Are there objects or variables that are consistently or reliably exposed to JavaScript in certain browsers, maybe? I know that some experimental APIs are vendor-prefixed, but that doesn't seem like a good idea for use in a commercial product, although I'm willing to stoop that low if needed. Any other possibilities?
A thought:
IE uses ActiveX (still does up to IE11, legacy), You can fairly easy deduce the fact that the user is using IE from looking at activeX availability, however if the security settings are on, you need to fall back on, guess what, other feature detection.
Chrome and Firefox both support the use of extensions, maybe detecting these extensions will help
Chrome has the window['chrome']['webstore'] object available in the global scope.
You can sort through the window object with Object.keys and look for vendor specific names like 'moz' or 'ms' or 'o'.
If you combine moz, ms and chrome-object you can sniff out the three largest browsers.
On a side note, feature detection is still the best option, not for the OP, but for the "I'm-just-getting-into-programming-and-I-like-to-know-how-I-sniff-out-a-browser-programmers" out there.
First off, just to be clear no inbound HTTP request is guaranteed to be accurate in saying who they are. In fact this is how some hackers operate by faking out the User-Agent field of the HTTP header. Most browser providers; however, do a good job of identifying who they are by saying so in the User-agent field of the inbound HTTP request header. The only problem working at the Javascript layer is that it is one layer too high for seeing the headers. However there are tricks and here's one of them :
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
alert(headers);
I found this after thinking about the problem a bit and knowing the Network side pretty well... You can read more about this here: Accessing the web page's HTTP Headers in JavaScript, in fact this question could be considered a duplicate of that answer, however, not everyone knows the HTTP layer. The code above is pretending to be a legitimate inbound request, and opens the document.location using a "Get", but it sends nothing. Without knowing the browser internals I am guessing that it is the DOM itself that is returning the already known header information. Just parse the User-Agent portion of he response and you are all set.

Detect full IE version in JavaScript

First of all, I am sorry if it was already asked, but I would like to know how I can detect (using JavaScript) which exact version of IE is running.
I already know window.navigator.userAgent and appVersion which returns ... MSIE 8.0 ..., but what I want is 8.0.6 or 8.0.9 (they have differences, some things that work in 8.0.9 do not work in 8.0.6).
I don't think you can detect this level of granularity via javascript - browser versions are detected from the user agent, and in IE8 the user agent doesn't go down to those versions.
More info on IE8 user agent strings here: http://www.useragentstring.com/_uas_Internet%20Explorer_version_8.0.php
If there are some things that only work in certain subversions I think you may have to do some sort of feature detection test rather than trying to ascertain the actual dot-dot-version...
What about navigator.appVersion ?
http://www.w3schools.com/jsref/prop_nav_appversion.asp
However, you still may need to grab the value using regular expressions.

how can a website detect smartphone model? [duplicate]

This question already has answers here:
Simple Smart Phone detection
(2 answers)
Closed 9 years ago.
How can a website detect the smartphone model of a device that requests a webpage?
Google Analytics can get that information as you can see in the image below:
I found this: http://blog.mobileesp.com/?p=177 but only a few phones are recognized by this script. I am looking for an PHP or Javascript solution
From Javascript you can read this property navigator.userAgent and PHP $_SERVER['HTTP_USER_AGENT'] both return you the browser version .
In my experience, the best method for detecting mobile/tablet is to use the PHP mobile_detect class which is updated regularly as new devices are released. Unfortunately, I don't know if it provides a way to get the different device types.
User agent parsing is the method you'll have to use, and if mobile_detect doesn't have it, it ought to at least give you a good starting point on how it's done.

Does Javascript features change by browser? [duplicate]

This question already has an answer here:
Why Javascript upload chunk sizes change by browser?
(1 answer)
Closed 8 years ago.
I wonder something about Javascript. Does Javascript features or behaviors change by browsers?
While I was working Javascript XMLHttpRequest upload method, I noticed that Internet Explorer sending small bytes but Firefox and Google chrome sending big bytes. So while I was sending big data with Firefox or Chrome, server is giving OutOfMemory exception.
I am editing post with image details.
No Javascript features doesn't change from browser to browser, it depends upon their Javascript rendering machine (interpreter is the difference).
For example:
Google - v8 engine
Safari - JavaScriptCore
yes there is some differences (a hanful actually)
here are some examples
1- accessing the float proparity
because float is a reserved keyword you can access it in ie with:
document.getElementById("id").style.styleFloat = "left";
while in fire fox it will be :
document.getElementById("id").style.cssFloat = "left";
2-to access a class attribute you can do the following in ie :
document.getElementById("id").getAttribute("className");
while in fire fox :
document.getElementById("id").getAttribute("class");
these are the things that i had an experience with . but mostly every one is using jquery now so no need to worry about those . but here are some articles about them
http://www.impressivewebs.com/7-javascript-differences-between-firefox-ie/
http://www.willowdesign.info/blog/tag/javascript-browser-differences/
JS cross browser inconsistencies/differences
http://technologypost.blogspot.com/2008/07/ie-vs-firefox-javascript-differences_05.html

Categories