[AnkiWeb] apps.ankiweb does not detect Android, redirects to Linux instead

Steps to replicate

  1. Open https://apps.ankiweb.net/ on Android (any browser)
  2. Scroll down to Download Anki
  3. 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)))


:star: 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
}


:star: 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);

Links

4 Likes

Logged on [AnkiWeb] apps.ankiweb does not detect Android, redirects to Linux instead · Issue #3636 · ankitects/anki · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.