Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect to appstore or google play [closed]

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>
like image 482
tony9099 Avatar asked Jun 28 '14 07:06

tony9099


People also ask

How do I stop ads from redirecting to Google Play?

Open Chrome on your Android device. To the right of the address bar, tap More, then tap Settings. Tap Site settings, then select Pop-ups and redirects. Switch Pop-ups and redirects to Block (You should then see “Block sites from showing pop-ups and redirects (recommended)” under Pop-ups and redirects)

Why Play store is opening and closing?

Clear the Google Play App Cache Excess data and info stored in the phone can cause your google play store to keep crashing and deleting them might just be the key to solving your issues. To clear the google play app cache do the following: Select settings on your phone. Go to storage.

Is Google App Store the same as Google Play store?

Just as iOS has its own app store, App Store, Android also has its own market called Google Play.


1 Answers

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>
like image 162
Govind Singh Avatar answered Oct 23 '22 07:10

Govind Singh