Skip to content

Instantly share code, notes, and snippets.

@dthphuong
Last active March 15, 2021 14:41
Show Gist options
  • Save dthphuong/7fa282b028e6116d30dd076adf7605a2 to your computer and use it in GitHub Desktop.
Save dthphuong/7fa282b028e6116d30dd076adf7605a2 to your computer and use it in GitHub Desktop.
Get OS platform
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<title>Memori - Connect with ease</title>
</head>
<body>
<script>
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
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)) {
os = 'Android';
} else if (!os && /Linux/.test(platform)) {
os = 'Linux';
}
return os;
}
switch (getOS()) {
case 'MacOS':
case 'iOS':
window.location.replace('https://apps.apple.com/vn/app/.....');
break;
case 'Android':
case 'Windows':
case 'Linux':
window.location.replace('https://play.google.com/store/apps/details?id=....');
break;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment