4

ユーザーエージェントがブラックベリーデバイスからのものであるかどうかを検出する次のhtmlがあります。ダウンロード URL をデバイス固有のものに置き換える方法を知りたいです。つまり、ユーザーのデバイスが 9800 の場合、9800 デバイスをダウンロードするようにユーザーに指示したいと思います。誰か助けてください。

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var ua = navigator.userAgent;
document.write("BB OS Version :: " + ua);
if (ua.indexOf("BlackBerry") >= 0) {
    if (ua.indexOf("Version/") >= 0) { // ***User Agent in BlackBerry 6 and BlackBerry 7
        Verposition = ua.indexOf("Version/") + 8;
        TotLenght = ua.length;
        document.write("BB OS Version :: " + ua.substring(Verposition, Verposition + 3));
    }
    else {// ***User Agent in BlackBerry Device Software 4.2 to 5.0
        var SplitUA = ua.split("/");
        document.write("BB OS Version :: " + SplitUA[1].substring(0, 3));
    }
}
</script>
<br>

<a href="http://mysite.com/download">Download</a>
</body>
</html> 
4

2 に答える 2

0

ダウンロードボタンに特定のスタイルのみが必要な場合は、ブラックベリーの場合はクラスを追加し、そうでない場合はクラスを削除します。

于 2013-01-21T12:15:26.553 に答える
0

これが役に立ち、あなたが求めていることを完全に理解できたことを願っています。ではごきげんよう。

<!DOCTYPE html>
<html>
<head>
</head>
<body>

  <a href="#" id="theLink">Download</a><br>

  <script type="text/javascript">

    function set_url(id, url) {
      document.getElementById(id).href = url; 
    }

    var ua = navigator.userAgent;
    document.write("BB OS Version :: " + ua);
    if (ua.indexOf("BlackBerry") >= 0) {
        if (ua.indexOf("Version/") >= 0) { // ***User Agent in BlackBerry 6 and BlackBerry 7
            Verposition = ua.indexOf("Version/") + 8;
            TotLenght = ua.length;
            document.write("BB OS Version :: " + ua.substring(Verposition, Verposition + 3));
            set_url("theLink", "http://www.google.com"); // go to User Agent in BlackBerry 6 and BlackBerry 7 url
        }
        else {// ***User Agent in BlackBerry Device Software 4.2 to 5.0
            var SplitUA = ua.split("/");
            document.write("BB OS Version :: " + SplitUA[1].substring(0, 3));
            set_url("theLink", "http://www.yahoo.com"); // go to User Agent in BlackBerry Device Software 4.2 to 5.0 url
        }
    }

  </script>

</body>
</html> 
于 2012-09-22T22:53:50.267 に答える