I need to create a common link that redirect to Android PlayStore or Apple App Store according to the os. This link will open in the browser.
Asked
Active
Viewed 426 times
1 Answers
2
You can do that using javascript:
function changeLink(){
document.getElementById('link').href= getMobileOperatingSystem();
}
function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
// Windows Phone must come first because its UA also contains "Android"
if (/windows phone/i.test(userAgent)) {
return "windows-link";
}
if (/android/i.test(userAgent)) {
return "android-link";
}
// iOS detection from: http://stackoverflow.com/a/9039885/177710
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return "ios-link";
}
return "ios-link"; // default
}
![](../../users/profiles/608388.webp)
Niraj Chauhan
- 6,765
- 9
- 41
- 73