javascripthtmljquerybrowsertwemoji

How to load a script only in specific Browsers?


What I want to do: I want to load load Twemoji in every Browser except Safari (Mobile/MacOS). I've tried to do it in JS, but it didn't work:

function IsSafari() {


var is_safari = navigator.vendor && navigator.vendor.indexOf('Apple') > -1 &&
               navigator.userAgent &&
               navigator.userAgent.indexOf('CriOS') == -1 &&
               navigator.userAgent.indexOf('FxiOS') == -1;
  return is_safari;

} if(!IsSafari){console.log("No reliable Emoji-set detected. Loading Twemoji from cdnjs");
$.getScript("https://cdnjs.cloudflare.com/ajax/libs/twemoji/12.0.4/2/twemoji.min.js", function() {
   twemoji.parse(document.body);
});}

Solution

  • here is how you can know if user is not using safari browser

    if(!(/constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification)))){
        console.log('Hey I am sure that you are not using safari browser ;)');
    }else{
        console.log('Apple user detected');
    }
    

    I took the code from this stackoverflow question answer How to detect Safari, Chrome, IE, Firefox and Opera browser?. Plz like this answer )