重定向到appstore或谷歌播放

ton*_*099 20 html javascript jquery android ios

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

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

我希望这个文件在我的服务器上的某个地方,包括检查设备类型是什么的java脚本代码,并重定向到方便的商店.也就是说,如果该设备是基于Android的谷歌播放和如果该设备是基于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>
Run Code Online (Sandbox Code Playgroud)

Gov*_*ngh 33

问题出在你的脚本标签上,你就错过了 );

顺便问一下你导入了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>
Run Code Online (Sandbox Code Playgroud)

  • 对于那些在这里结束的人,我建议将链接重定向视为一种解决方案,因为它通常更便宜(资源方面).我与此服务没有任何关系,但http://onelink.to/是一个很好的例子 - 或者你自己的内部链接转发 - 这可以通过不必加载任何javascript(jquery等)来改善加载时间 (2认同)