我需要创建一个根据操作系统重定向到Android PlayStore或Apple App Store的公共链接。此链接将在浏览器中打开。
答案 0 :(得分:2)
您可以使用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
}