@manhnguyenv

Welcome to my blog!

Detect Browser

September 18, 2018 22:26

Detect Browser (edit)

JavaScript Error and Status

https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide/console/error-and-status-codes#javascript-run-time-errors

JavaScript Detect Browser

https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser/9851769

<!DOCTYPE html>
<html>
   <head>
      <script>
         document.addEventListener('DOMContentLoaded', function () {
             // Opera 8.0+
             var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
         
             // Firefox 1.0+
             var isFirefox = typeof InstallTrigger !== 'undefined';
         
             // Safari 3.0+ "[object HTMLElementConstructor]" 
             var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);
         
             // Internet Explorer 6-11
             var isIE = /*@cc_on!@*/false || !!document.documentMode;
         
             // Edge 20+
             var isEdge = !isIE && !!window.StyleMedia;
         
             // Chrome 1+
             var isChrome = !!window.chrome && !!window.chrome.webstore;
         
             // Blink engine detection
             var isBlink = (isChrome || isOpera) && !!window.CSS;
         
             var output = 'Detecting browsers by ducktyping:<hr>';
             output += 'isFirefox: ' + isFirefox + '<br>';
             output += 'isChrome: ' + isChrome + '<br>';
             output += 'isSafari: ' + isSafari + '<br>';
             output += 'isOpera: ' + isOpera + '<br>';
             output += 'isIE: ' + isIE + '<br>';
             output += 'isEdge: ' + isEdge + '<br>';
             output += 'isBlink: ' + isBlink + '<br>';
             document.body.innerHTML = output;
         });
      </script>
   </head>
   <body></body>
</html>

Categories

Recent posts