3

Does anyone have any javascript code to detect Safari and Chrome running on Mac OS so I can apply css for each browser?

bPratik
  • 6,894
  • 4
  • 36
  • 67
asdf1234
  • 127
  • 4
  • 10
  • This might help http://stackoverflow.com/a/9851769/1823841 – palaѕн Jun 05 '13 at 09:19
  • 2
    This is a bad idea mostly. Care to tell us a bit more about your use case? – georg Jun 05 '13 at 09:19
  • This is a very bad idea, unless you care to explain why you are doing this, and why feature detection won't be the better path, you will get the wrath of the community! :) – bPratik Jun 05 '13 at 09:27
  • For example I need it to properly use 3rd party java applet ;) – tester.one Jul 16 '13 at 09:38
  • 1
    @thg435 I agree, BUT there are a lot of scenarios where this is necessary, for example when Safari on Mac messes up fonts (because Mac renders differently heights etc.). It's bad practive for sure, but if your 50.000€-client wants his custom webfonts, well, then you do it. – Sliq Jun 06 '14 at 17:39

2 Answers2

3
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";    

var isOpera = !!window.opera || navigator.userAgent.indexOf('Opera') >= 0;
    // Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
    var isFirefox = typeof InstallTrigger !== 'undefined';   // Firefox 1.0+
    var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
    // At least Safari 3+: "[object HTMLElementConstructor]"
    var isChrome = !!window.chrome;                          // Chrome 1+
    var isIE = /*@cc_on!@*/false;                            // At least IE6

    if(OSName == "MacOS" && isChrome == true) 
    {
        alert('chrome on MAC OS')
    }
Harsha Venkataramu
  • 2,887
  • 1
  • 34
  • 58
-2

Instead of browser detection, you should go for feature detection. You should also give a try for Modernizr.js

Praveen
  • 55,303
  • 33
  • 133
  • 164