根据浏览器更改下载网址


Change download url depending on browser

我想做的是有一个桌面浏览器的普通链接,如下所示:

<div style="text-align: center;">
   <a href="http://db.tt/b6ecH2Dh">
      <img src="img/download.gif"/>
</div>

但是当iOS用户单击链接时,它应该打开一个不同的链接,如下所示:

<div style="text-align: center;">
   <a href="cydia://package/bla">
       <img src="img/download.gif"/>
</div>

我可以用JavaScript或PHP来做吗?如果是这样,如何做?

编辑要使用javascript执行此操作,请将此脚本放入HTML文档中

<script type="text/javascript">
if (navigator.userAgent.match(/Mac OS X/i)) {
                document.getElementById('down').href="http://www.google.com";
        }
</script>
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) 
{
     document.getElementById('download_link').href = "http://iphonedl";
}

应该工作

http://davidwalsh.name/detect-iphone

你可以同时使用两者:

  • .PHP
  • jQuery

有关示例,请参阅 http://davidwalsh.name/detect-ipad