Answers for "detect user browser javascript"

5

javascript get browser

//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';
    }
}
Posted by: Guest on July-31-2019
1

detect user browser javascript

if (navigator.userAgent.includes('Safari')) {
  // the user is running Safari
  // do something useful
}
Posted by: Guest on February-03-2021

Code answers related to "detect user browser javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language