Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getBrowser() {
- var userAgent = navigator.userAgent,
- matched = userAgent.match(/(chrome|firefox|opera|safari|msie|trident(?=/))/?s*(d+)/i) || [],
- version,
- browser = { name: '', version: '' };
- // IE Shells; I gaurantee that you will see this with Dell branded OEM IE 11 installs.
- if(/trident/i.test(matched[1])) {
- version = /brv[ :]+(d+)/g.exec(userAgent) || [];
- return { name: 'Internet Explorer', version: (version[1] || '') };
- }
- // Not Chrome; at first glance this looks like a block for chrome identification, but
- // its actually Opera.
- if(matched[1] === 'Chrome') {
- version = userAgent.match(/b(OPR|Edge)/(d+)/);
- if(version !== null) {
- return { name: version[1].replace('OPR', 'Opera'), version: version[2] };
- }
- }
- // The rest; Chrome, Safari, etc
- matched = matched[2] ? [matched[1], matched[2]] : [navigator.appName, navigator.appVersion, '-?'];
- if((version = userAgent.match(/version/(d+)/i)) !== null) {
- matched.splice(1, 1, version[1]);
- }
- browser.name = (matched[0] !== "") ? matched[0] : "Unknown";
- browser.version = (matched[1] !== "") ? matched[1] : "Unknown";
- return browser;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement