【问题标题】:redirect to appstore or google play [closed]重定向到应用商店或谷歌播放[关闭]
【发布时间】:2014-08-19 07:37:58
【问题描述】:

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

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>

【问题讨论】:

  • 尝试用&lt;/script&gt;替换&lt;/javascript&gt;
  • 另外,如下所述,您的脚本末尾缺少右括号。

标签: javascript android jquery html ios


【解决方案1】:

问题在于您的脚本标签,您缺少);

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

【讨论】:

  • 对于那些在这里结束的人,我建议将链接重定向视为一种解决方案,因为它通常更便宜(资源方面)。我与此服务没有任何关系,但onelink.to 是一个很好的例子 - 或者您自己的内部链接转发 - 这通过不必加载任何 javascript(jquery 等)来缩短加载时间
  • 我建议避免不必要地使用 Jquery。尝试使用: DOMContentLoaded 处的 document.addEventListener 代替。避免使用 Jquery 执行任何简单任务的重要原因是减少时间加载和网络消耗。 Jquery 加载脚本中的所有库,即使是您永远不会使用的库。使用移动网络的移动用户会感谢您节省一些带宽。
猜你喜欢
  • 2016-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多