Skip to content

Instantly share code, notes, and snippets.

@ali-master
Last active January 4, 2017 09:38
Show Gist options
  • Save ali-master/26da7caa3d934104d1fee8aef6b849ae to your computer and use it in GitHub Desktop.
Save ali-master/26da7caa3d934104d1fee8aef6b849ae to your computer and use it in GitHub Desktop.
Information About Client web Browser

Information About Client web Browser

var browserInfo = function () {
    var ua = navigator.userAgent.toLowerCase();
    var matchs = ua.match(/(opera)\/([\d\.]+)/i) || ua.match(/(msie) ([\d\.]+)/i) || ua.match(/(firefox)\/([\d\.]+)/i) || ua.match(/(chrome)\/([\d\.]+)/i) || ua.match(/(safari)\/([\d\.]+)/i) || [];
    return {
        name: matchs[1] || 'unknown',
        version: matchs[2] || 'unknown',
        isTouch: 'ontouchend' in document
    }
}

Usage

window["browserInfo"] = new browserInfo();

const name = window.browserInfo.name;
const version = window.browserInfo.version;
const isTouchSupport = window.browserInfo.isTouch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment