Android 使用nodejs重定向到PlayStore或AppStore的公共链接

Android 使用nodejs重定向到PlayStore或AppStore的公共链接,android,ios,node.js,hyperlink,Android,Ios,Node.js,Hyperlink,我需要创建一个公共链接,根据操作系统重定向到Android PlayStore或Apple App Store。此链接将在浏览器中打开。您可以使用javascript: function changeLink(){ document.getElementById('link').href= getMobileOperatingSystem(); } function getMobileOperatingSystem() { var userAgent = navigator.use

我需要创建一个公共链接,根据操作系统重定向到Android PlayStore或Apple App Store。此链接将在浏览器中打开。

您可以使用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
}

您可以使用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
}