This question has already been discussed here: JavaScript: how do I know if the browser is a Chrome user?
Please try the following:
var isChromium = window.chrome; if(isChromium){ // is Google chrome } else { // not Google chrome }
But a more complete and accurate answer would be this, since IE11, IE Edge and Opera will also return true for window.chrome
So use below:
// please note, // that IE11 now returns undefined again for window.chrome // and new Opera 30 outputs true for window.chrome // and new IE Edge outputs to true now for window.chrome // so use the below updated condition var isChromium = window.chrome, vendorName = window.navigator.vendor, isOpera = window.navigator.userAgent.indexOf("OPR") > -1, isIEedge = window.navigator.userAgent.indexOf("Edge") > -1; if(isChromium !== null && isChromium !== undefined && vendorName === "Google Inc." && isOpera == false && isIEedge == false) { // is Google chrome } else { // not Google chrome }
We recommend using jQuery.browser over messages. But the jQuery API recommends not using this method .. (see DOCS in the API ). And declares that its functionality can be transferred to the plugin supported by the team in a future version of jQuery.
The jQuery API recommends using jQuery.support .
The reason is that "jQuery.browser" uses a user agent that can be tampered with, and is actually deprecated in later versions of jQuery. If you really want to use $ .browser .. Here is a link to the standalone jQuery plugin since it was removed from jQuery version 1.9.1. https://github.com/gabceb/jquery-browser-plugin
Better to use object object detection instead of browser detection.
Also, if you use the Google Chrome Inspector and go to the console tab. Type in a "window" and press "Enter." Then you can view the DOM properties for the "window object". When you destroy an object, you can view all the properties, including the "chrome" property.
Hope this helps, although the question was related to jQuery. But sometimes direct javascript is simpler!
Jonathan Marzullo Oct 20 2018-12-12T00: 00Z
source share