0

I am trying to add a width to a div if browser is safari. I am trying the below algorithm to check through javascript. If there any css or less only code to check if browser is safari and add with to div only on safari? or this is only possible with javascript or js libraries?

 var userAgent = navigator.userAgent.toLowerCase(); 
    if (userAgent .indexOf('safari')!=-1){ 
       if(userAgent .indexOf('chrome')  > -1){
         //browser is chrome
       }else if((userAgent .indexOf('opera')  > -1)||(userAgent .indexOf('opr')  > -1)){
         //browser is opera 
       }else{
        //browser is safari, add css
       }
    }
Kurkula
  • 6,386
  • 27
  • 127
  • 202
  • 2
    did you check [css hack sufari] (https://stackoverflow.com/questions/16348489/is-there-a-css-hack-for-safari-only-not-chrome) – Bhunesh Satpada Jun 26 '17 at 05:12

1 Answers1

-1

This code works on most of the browsers:

<!DOCTYPE html>
<html>
<body>
<div id="example"></div>

<script>

txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>";

document.getElementById("example").innerHTML=txt;

</script>

</body>
</html>
kode master
  • 100
  • 1
  • 15