重定向到应用商店或谷歌播放[关闭]

问题描述 投票:0回答:1

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

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

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

到目前为止我已经尝试过这个,但它不起作用。

<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>
javascript android jquery html ios
1个回答
50
投票

问题出在你的脚本标签上,你丢失了

);

顺便问一下,你导入了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>
© www.soinside.com 2019 - 2024. All rights reserved.