So I have a website, and what I want is that when the open my website: www.example.com/download.html I want to first detect if the device is iOS device or Android device, and then redirect to another link, for example www.google.com (just an example). I want different link for different OS. Any tips on how I can manage this? :)
On your device, go to the Home screen (the one with all the icons), and tap on the Settings icon. Scroll down and tap on About phone or About tablet. Some information will appear. If one of the lines of information says Android with a version number, you have an Android device.
matchMedia() The Window interface's matchMedia() method returns a new MediaQueryList object that can then be used to determine if the document matches the media query string. For example, a device whose screen width does not exceed 768px is considered a mobile device: const isMobile = window.
You can use the user agent string to detect different kinds of devices like so:
function androidOrIOS() {
const userAgent = navigator.userAgent;
if(/android/i.test(userAgent)){
return 'android';
}
if(/iPad|iPhone|iPod/i.test(userAgent)){
return 'ios';
}
}
You can use Navigator to determine the type of device
function navigate() {
if((/Mobi|Android/i.test(navigator.userAgent))){
window.location.href = 'android url ';
}
if(/Mobi|iPad|iPhone|iPod/i.test(navigator.userAgent)){
window.location.href = 'ios url ';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With