0

I have a web app (Sleepyheads) and have made it into an android app. I want a popup asking to download the app ONLY on android devices. How can I do this?

I'm using html 5 and VS code

Rana
  • 2,500
  • 2
  • 7
  • 28
  • Does [this](https://stackoverflow.com/questions/38241480/detect-macos-ios-windows-android-and-linux-os-with-js) answer your question? Or [this](https://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-details-using-javascript)? – Alex Wayne Oct 31 '21 at 07:18
  • did this question help you? https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser – il4mb Oct 31 '21 at 07:40

5 Answers5

1

you have to use javascript to find what is your user device.

this code says to you what is user os and device is.

navigator.userAgent
0

You can use navigator.userAgent to get the browser string.

You will get reply like this.

'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Mobile Safari/537.36'

You can then check for Android word with includes

let browsertype=navigator.userAgent;
if(browsertype.includes("Android")){
    //Navigate to Play store link or other URL
    alert("Please follow the link to download App");
}
Hemal
  • 3,682
  • 1
  • 23
  • 54
0

You can find this type of info in the window.navigator.userAgent. In order to better work with that info, you can use a parser, something like https://github.com/faisalman/ua-parser-js. Then is just a condition based on the OS.

0

You can do this by checking OS and then writing condition in DOM, that will show popup only when the desired OS is accessed from.

let os = navigator.appVersion;
if(os == "windows")
{
  //display popup
}
Hemal
  • 3,682
  • 1
  • 23
  • 54
  • OS string is not straight forward , to know about that , you can visit : https://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-details-using-javascript – Manoj Mulakala Oct 31 '21 at 07:27
0

With Javascript you can check which operating system is being used

window.clientInformation.oscpu
  • This `oscpu` property doesn't exist in Chrome on macOS (and probably others). And the docs for `clientInformation` recommend using `navigator` instead. – tony19 Oct 31 '21 at 07:33