4

I have the following html which detects if the useragent is from a blackberry device. I would like to know how to replace the download url with a one specific for a device ie, i would like to direct the user to download for 9800 device if his device is 9800. please can anyone help?

<!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> 
user1121332
  • 217
  • 2
  • 8
  • 1
    Check this link, http://stackoverflow.com/questions/4365246/how-to-change-href-of-a-tag-on-button-click-through-javascript/4365272#4365272. – Rupak Sep 19 '12 at 16:10

2 Answers2

0

i hope that this helps and that i fully understood what you are asking. all the best.

<!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> 
Sean M
  • 1,587
  • 16
  • 15
0

If you only want specific styling for your download button, then just add a class if it is a Blackberry, and take it away if it isn't.

hitecherik
  • 414
  • 2
  • 13