skip to Main Content

I want to remove this button and its functionality for Firefox and Safari, but not on Chrome

<button id="start" class="left tooltipped" data-tooltip="Record" style="padding: 16px;border-radius: 100%;position: relative;background: #EB455F;top: 12px;"></button>

2

Answers


  1. Hi You can detect the browser and add a class to your button or remove the button and functionality.
    Working Example: https://codepen.io/sethuramancbe/pen/abRBmGd

    function fnBrowserDetect(){
                     
             let userAgent = navigator.userAgent;
             let browserName;
             
             if(userAgent.match(/chrome|chromium|crios/i)){
                 browserName = "chrome";
               }else if(userAgent.match(/firefox|fxios/i)){
                 browserName = "firefox";
               }  else if(userAgent.match(/safari/i)){
                 browserName = "safari";
               }else if(userAgent.match(/opr//i)){
                 browserName = "opera";
               } else if(userAgent.match(/edg/i)){
                 browserName = "edge";
               }else{
                 browserName="No browser detection";
               }
             
              return browserName;       
      }
    
    const browser = fnBrowserDetect();
    
    
    const btn = document.getElementById('start');
    const hideIn = ['firefox', 'safari'];
    if (hideIn.includes(browser)) {
      btn.classList.add("hide");
    } 
    
    Login or Signup to reply.
  2. You can use a regular expression to match any instance of "Firefox/" in the user agent string.
    This will match all versions of Firefox, regardless of the operating system or other details of the user agent string.

    // Check if the browser is Firefox
    if (/Firefox//.test(navigator.userAgent)) {
      // Remove the button and its functionality
      var button = document.getElementById("start");
      button.parentNode.removeChild(button);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search