Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

ios

ipad

This is what I have on my 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.

like image 932
Monica Avatar asked Nov 25 '13 21:11

Monica


People also ask

Why Safari is not working on iPad?

If Safari opens but is unresponsive, clear your browsing history to see if that makes it work more effectively. Disable Safari suggestions. Safari suggestions can sometimes cause Safari to crash. Try disabling them by tapping Settings > Safari > then toggle off the Safari Suggestions switch.

Why do some websites not load on iPhone?

Check Cellular Data Settings If you can load web pages on Wi-Fi, but pages do not load on cellular data, you must check mobile data settings. For that, go to Settings > Cellular data/Mobile data. Scroll down and make sure the toggle next to Safari is green. If it's off, turn it on.


1 Answers

Use touchend event via jQuery on all anchor tags. 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:

$(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    
        });     
    }
});
like image 164
Mike Barwick Avatar answered Oct 11 '22 04:10

Mike Barwick