用于iPhone / iPod Touch / iPad的safari(ios)中的锚标签

时间:2013-11-25 21:59:58

标签: ios html5 ipad

这就是我在HTML5上的内容

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

并且在chrome,FF,android上工作正常,但似乎无法在iPad上运行。

1 个答案:

答案 0 :(得分: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    
        });     
    }
});