简体   繁体   English

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

[英]anchor tag not working in safari (ios) for iPhone/iPod Touch/iPad

This is what I have on my HTML5 这就是我对HTML5的看法

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

and works fine on chrome, FF, android but doesn't seem to work on iPad. 并且在chrome,FF,android上工作正常,但似乎不适用于iPad。

Use touchend event via jQuery on all anchor tags. 在所有锚标签上通过jQuery使用touchend事件。 For example: 例如:

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

If you want to make the above iPhone and iPad specific function only, check to see if the "device" is an iPad, iPhone, etc. Like so: 如果您只想制作上述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    
        });     
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM