2013-11-25 21 views
11

这是我对我的HTML5锚标记在Safari不工作(IOS)的iPhone/iPod的触摸/ iPad的

<div class="google-play"> 
    <a href="http://example.com" role="button"> 
     <img src="img/google-play-btn.png"/>                  
    </a> 
</div> 

和铬工作正常,FF,安卓但似乎并没有工作在iPad上。

+1

而不工作,你的意思是什么? –

+0

你点击并没有任何反应 – Monica

+0

我刚刚在Safari中打开了你的html页面,点击并且按照预期处理了链接。与http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_href_anchor一样。你必须准确解释什么是问题。 –

回答

14

通过jQuery在所有锚标签上使用touchend事件。例如:

$(function() {  
    $('a').on('click touchend', function() { 
     var link = $(this).attr('href'); 
     window.open(link,'_blank'); // opens in new window as requested 

     return false; // prevent anchor click  
    });  
}); 

如果你想使上面的iPhone和iPad的具体功能而已,请检查“设备”是一个iPad,iPhone等像这样:

$(function() { 

    IS_IPAD = navigator.userAgent.match(/iPad/i) != null; 
    IS_IPHONE = (navigator.userAgent.match(/iPhone/i) != null) || (navigator.userAgent.match(/iPod/i) != null); 

    if (IS_IPAD || IS_IPHONE) { 

     $('a').on('click touchend', function() { 
      var link = $(this).attr('href'); 
      window.open(link,'_blank'); // opens in new window as requested 

      return false; // prevent anchor click  
     });  
    } 
}); 
+0

点击仍然适用于Chrome和Firefox吗? – Monica

+0

是的,女士!跨平台解决方案我的朋友。 :) –

+0

好的,谢谢! – Monica