0

enter image description hereI have a voice recorder and some of the browsers do not support. It works in Firefox, but it does not work in Opera, Chrome and Edge. How can I fixed that ?

function myFunction() { 
  if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) 
 {
     alert('Opera');
 }
 else if(navigator.userAgent.indexOf("Chrome") != -1 )
 {
     alert('Chrome');
 }
 else if(navigator.userAgent.indexOf("Safari") != -1)
 {
     alert('Safari');
 }
 else if(navigator.userAgent.indexOf("Firefox") != -1 ) 
 {
      alert('Firefox');
 }
 else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
 {
   alert('IE'); 
 }  
 else 
 {
    alert('unknown');
 }
 }

 myFunction();
petra
  • 2,642
  • 2
  • 20
  • 12
Oğuzhan
  • 73
  • 1
  • 8
  • 1
    Tip: Don't detect the browser, **detect the capability**. User agent strings are just a giant pile of garbage that doesn't make any sense and can't be trusted. If you are committed to "browser sniffing", at least use a [well-tested library](https://www.npmjs.com/package/detect-browser). – tadman Mar 19 '21 at 08:36
  • Does this answer your question? [How to detect Safari, Chrome, IE, Firefox and Opera browser?](https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser) – Wendelin Mar 19 '21 at 08:37
  • 1
    Don't try to use user agent strings - they can be anything the browser fancies as @tadman so elegantly puts it. MDN has info on feature detection at [link]https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Feature_detectionand also says: "don't confuse feature detection with browser sniffing (detecting what specific browser is accessing the site) — this is a terrible practice that should be discouraged at all costs" – A Haworth Mar 19 '21 at 08:49

0 Answers0