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
CodePudding user response:
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
CodePudding user response:
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");
}
CodePudding user response:
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.
CodePudding user response:
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
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
With Javascript you can check which operating system is being used
window.clientInformation.oscpu