Steps to replicate
- Open https://apps.ankiweb.net/ on Android (any browser)
- Scroll down to Download Anki
- Should appear as iOS/Android, Redirects to Linux instead
Tested with Brave, Samsung, Chrome browsers
Current Script
var os = navigator.platform;
var ua = navigator.userAgent;
if (os == "Win32") {
$("a[href=#windows]").tab("show");
} else if (os == "MacIntel") {
$("a[href=#mac]").tab("show");
} else if (!!os.match(/Linux/i)) {
$("a[href=#linux]").tab("show");
} else {
if (!!(ua.match(/(iPad|iPhone|iPod)/i) || !!ua.match(/Android/i))) {
$("a[href=#ios]").tab("show");
} else {
$("#unknown").show();
}
}
Ideas
(!!os.match(/Linux/i))
could be automatically assigning every Android device as Linux before !!ua.match(/Android/i)))
Five Methods to Detect Mobile Browsers in JavaScript
if (/Mobi|Android|iPhone/i.test(navigator.userAgent)) {
// Current device is a mobile device
}
// Alternate approach
if (
navigator.userAgent.match(/Mobi/i) ||
navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/iPhone/i)
) {
// Current device is a mobile device
}
https://dev.to/timhuang/a-simple-way-to-detect-if-browser-is-on-a-mobile-device-with-javascript-44j3
const isMobile = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);