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


这就是我对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上运行。


3403
2017-11-25 21:59


起源

如果不工作,你的意思究竟是什么? - A-Live
你点击,没有任何反应 - Monica
我刚刚在Safari上打开了你的html页面,点击了该链接并按预期处理了。与...相同 w3schools.com/tags/tryit.asp?filename=tryhtml5_a_href_anchor。你必须准确地解释什么是问题。 - A-Live
谢谢,有人解决了。他们给了我这个跨平台的解决方案。 - Monica


答案:


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

$(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    
        });     
    }
});

14
2017-11-25 22:03



点击是否仍适用于Chrome和Firefox? - Monica
是的女士!跨平台解决方案我的朋友。 :) - Mike Barwick
好的,谢谢! - Monica
如果这适合您,请不要忘记接受。 ;) - Mike Barwick
但是如何在新页面中打开它?这将在同一页面上打开。如果我想在新页面打开怎么办? - Monica