Android 重定向到应用商店或谷歌播放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24464602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:13:34  来源:igfitidea点击:

redirect to appstore or google play

javascriptandroidjqueryhtmlios

提问by tony9099

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

我将按以下格式向我的客户发送该应用程序的链接

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

http://goo.gl.com/downloadtheapp(或其他)

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.

我希望这个文件位于我的服务器上的某个位置,其中包含检查设备类型并重定向到便利店的 java 脚本代码。也就是说,如果设备是基于 android 的,则使用 google play,如果设备是基于 ios 的,则使用 appstore。

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>

回答by Govind Singh

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

问题出在您的脚本标签上,而您丢失了 );

and by the way did you imported jQuery?

顺便说一下,你导入了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>