redirect to appstore or google play

42,978

The problem is with your script tag and you are missing );

And by the way, did you import jQuery?

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<script>
    $(document).ready(function (){
        if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
            window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
        }
        if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
            window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
        }
    });
</script>
Share:
42,978
tony9099
Author by

tony9099

worst programmer on the entire planet.

Updated on July 20, 2022

Comments

  • tony9099
    tony9099 almost 2 years

    I will send my clients the link for the app in the following format

    http://goo.gl.com/downloadtheapp (or whatever)

    I want this file be somewhere on my server that includes java script code that checks what is the device type and redirects to the convenient store. that is, google play if the device was android based and appstore if the device was ios based.

    till now I tried this, but it does not work.

    <html>
    <head>
    <script type="text/javascript">
            $(document).ready(function () 
        {
            if(navigator.userAgent.toLowerCase().indexOf("android") > -1)
            {
                window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
            }
            if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1)
            {
                window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
            }
        }
    </javascript>
    </head>
    <body>
    </body>
    </html>