detect browser javascript
JavaScript
//gets the type of browser
function detectBrowser() {
if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) {
return 'Opera';
} else if(navigator.userAgent.indexOf("Chrome") != -1 ) {
return 'Chrome';
} else if(navigator.userAgent.indexOf("Safari") != -1) {
return 'Safari';
} else if(navigator.userAgent.indexOf("Firefox") != -1 ){
return 'Firefox';
} else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) {
return 'IE';//crap
} else {
return 'Unknown';
}
} agent = {browser:{name:null,version:null,v:null,userAgent:null,app:null,os:null},mobile:false,pointlock:false};
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
agent.pointlock = 'pointerLockElement' in document ||
'mozPointerLockElement' in document ||
'webkitPointerLockElement' in document;
// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
browserName = "Opera";
fullVersion = nAgt.substring(verOffset+6);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
browserName = "Safari";
fullVersion = nAgt.substring(verOffset+7);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) <
(verOffset=nAgt.lastIndexOf('/')) )
{
browserName = nAgt.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset+1);
if (browserName.toLowerCase()==browserName.toUpperCase()) {
browserName = navigator.appName;
}
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
fullVersion=fullVersion.substring(0,ix);
majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
fullVersion = ''+parseFloat(navigator.appVersion);
majorVersion = parseInt(navigator.appVersion,10);
}
agent.browser.name = browserName;
agent.browser.version = fullVersion;
agent.browser.v = majorVersion;
agent.browser.app = navigator.appName;
agent.browser.userAgent = navigator.userAgent;
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
agent.browser.os = OSName;
agent.mobile = (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
Also in JavaScript:
- Title
- javacript count properties
- Category
- JavaScript
- Title
- is js dead
- Category
- JavaScript
- Title
- console.log('Hi there!');
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- compare two arrays javascript
- Category
- JavaScript
- Title
- angular add object to array
- Category
- JavaScript
- Title
- convert string to char array javascript
- Category
- JavaScript
- Title
- array length for boolean in javascript
- Category
- JavaScript
- Title
- area of a circle
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- how to get value in array object value using for loop in javascript
- Category
- JavaScript
- Title
- how to add validator to formgroup
- Category
- JavaScript
- Title
- how to convert audio blocb to base64 string
- Category
- JavaScript
- Title
- how to find unique elements in array in javascript
- Category
- JavaScript
- Title
- how to link javascript to html
- Category
- JavaScript
- Title
- chrome extension get current tab from popup
- Category
- JavaScript
- Title
- Bots server count discord js
- Category
- JavaScript
- Title
- add month date now javascript
- Category
- JavaScript
- Title
- discord.js
- Category
- JavaScript
- Title
- How to append to a file in Node?
- Category
- JavaScript
- Title
- export function javascript
- Category
- JavaScript
- Title
- hover vanilla javascript
- Category
- JavaScript
- Title
- express how to access ajax post data
- Category
- JavaScript
- Title
- bq show pretty json
- Category
- JavaScript
- Title
- filter advantages in js
- Category
- JavaScript
- Title
- convert json to csv npm
- Category
- JavaScript
- Title
- async await javascript stack overflow
- Category
- JavaScript
- Title
- append new element for each value in array d3.js
- Category
- JavaScript
- Title
- add dynamic value to id attribute in angular 8
- Category
- JavaScript
- Title
- discord.js tagging the author
- Category
- JavaScript
- Title
- export component in
- Category
- JavaScript
- Title
- get args nodejs
- Category
- JavaScript
- Title
- abstraction in javascript
- Category
- JavaScript
- Title
- choose random from array javascript
- Category
- JavaScript
- Title
- how to remove duplicate array object in javascript
- Category
- JavaScript
- Title
- document queryselector click event
- Category
- JavaScript
- Title
- create array with specific size javascript
- Category
- JavaScript
- Title
- add char in specific index stirng javascript
- Category
- JavaScript
- Title
- discord js bot leave voice channel
- Category
- JavaScript
- Title
- boucle foreach js
- Category
- JavaScript
- Title
- discord.js start code
- Category
- JavaScript
- Title
- express get params after ?
- Category
- JavaScript
- Title
- hover jquery
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- convert json to 2d array
- Category
- JavaScript
- Title
- array insertion javascript
- Category
- JavaScript
- Title
- bootstrap modal remove gray background
- Category
- JavaScript
- Title
- add variable numerically in javascript
- Category
- JavaScript
- Title
- ajax .put
- Category
- JavaScript
- Title
- how to add row in angular dynamically
- Category
- JavaScript
- Title
- get current directory vbscript
- Category
- JavaScript
- Title
- clear terminal node js
- Category
- JavaScript
- Title
- how do you remove a remove element from array in javascript
- Category
- JavaScript
- Title
- check array values equal js
- Category
- JavaScript
- Title
- how to open a new html page on button click in javascript
- Category
- JavaScript
- Title
- change the value in checkbox by button react
- Category
- JavaScript
- Title
- calling function from function object javascript
- Category
- JavaScript
- Title
- auto refresh page javascript
- Category
- JavaScript
- Title
- include jquery
- Category
- JavaScript
- Title
- how to mass comment in p5
- Category
- JavaScript
- Title
- javascript adding an array to an array
- Category
- JavaScript
- Title
- how to loop object javascript
- Category
- JavaScript
- Title
- how to make vue app talk to backend on 8000
- Category
- JavaScript
- Title
- get attribute value jquery href
- Category
- JavaScript
- Title
- check row empty array javascript
- Category
- JavaScript
- Title
- comment in jsp file
- Category
- JavaScript
- Title
- expresiones ternarias javascript
- Category
- JavaScript
- Title
- export apk react native
- Category
- JavaScript
- Title
- javascript add option element to select
- Category
- JavaScript
- Title
- find class using jquery
- Category
- JavaScript
- Title
- add table row jQuery
- Category
- JavaScript
- Title
- For-each over an array in JavaScript
- Category
- JavaScript
- Title
- angular for loop
- Category
- JavaScript
- Title
- declare function javascript
- Category
- JavaScript
- Title
- how to call javascript method using selectlist on change in vf page
- Category
- JavaScript
- Title
- arrow function javascript ie11
- Category
- JavaScript
- Title
- bind and unbind jquery validation
- Category
- JavaScript
- Title
- font awesome 4.7 cdn
- Category
- JavaScript
- Title
- access session data from ejs view
- Category
- JavaScript
- Title
- .pop js
- Category
- JavaScript
- Title
- aws amplify get JWT TOKEN
- Category
- JavaScript
- Title
- how to append select option in jquery
- Category
- JavaScript
- Title
- how to remove link in image in jquery
- Category
- JavaScript
- Title
- javascript click on element
- Category
- JavaScript
- Title
- firestore update map
- Category
- JavaScript
- Title
- floor in js
- Category
- JavaScript
- Title
- how to set height of material ui dialog react
- Category
- JavaScript
- Title
- check if checkbox is checked javascript
- Category
- JavaScript
- Title
- dynamic for loop react
- Category
- JavaScript
- Title
- email regex javascript
- Category
- JavaScript
- Title
- add element to array javascript
- Category
- JavaScript
- Title
- change width in js
- Category
- JavaScript
- Title
- electron jquery
- Category
- JavaScript
- Title
- angular img
- Category
- JavaScript
- Title
- how to remove spaces from strings javascript
- Category
- JavaScript
- Title
- angular npm angular material
- Category
- JavaScript
- Title
- case in javascript
- Category
- JavaScript
- Title
- adonisjs livereload
- Category
- JavaScript
- Title
- if else practice javascript
- Category
- JavaScript
- Title
- filter in react native
- Category
- JavaScript