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

后端 未结 1 1619
天命终不由人
天命终不由人 2021-02-04 11:59

This is what I have on my HTML5


      
1条回答
  •  -上瘾入骨i
    2021-02-04 12:57

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

    0 讨论(0)
提交回复
热议问题