"Detect Operation System with Javascript and user agent device"
Bootstrap 3.1.0 Snippet by muhittinbudak

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Strait"> <div class="container" style="font-family: 'Strait', sans-serif;"> <div class="row"> <h1>Detect Operation System with Javascript and user agent device</h1> <h3 id="ssonuc" class="well" style="background-color:yellow"></h3> </div> </div>
$(document).ready(function(){ //----------------- function getOS() { const userAgent = window.navigator.userAgent, platform = window.navigator?.userAgentData?.platform || window.navigator.platform, macosPlatforms = ['macOS', 'Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'], iosPlatforms = ['iPhone', 'iPad', 'iPod']; let os = null; if (macosPlatforms.indexOf(platform) !== -1) { os = 'MacOS'; } else if (iosPlatforms.indexOf(platform) !== -1) { os = 'iOS'; } else if (windowsPlatforms.indexOf(platform) !== -1) { os = 'Windows'; } else if (/Android/.test(userAgent)) { if (/Huawei|HUAWEI|HarmonyOS|EMUI/.test(userAgent)) { os = 'Huawei'; } else { os = 'Android'; } } else if (/Linux/.test(platform)) { os = 'Linux'; } return os; } var sonuc = ""; sonuc = getOS(); //if( (A && !B) || (B && !A) ) { ... } $("#ssonuc").text("The operating system of your device is; " + sonuc ).css({ "background-color" : "green", "color" : "white"}); //----------------------- });

Related: See More


Questions / Comments: