简体   繁体   English

Touchstart 单击事件不适用于 iPhone / iPade

[英]Touchstart click event is not working for iPhone / iPade

I've written an event to open new browser tab ( window.open ) by jQuery like below:我编写了一个事件来通过 jQuery 打开新的浏览器选项卡( window.open ),如下所示:

$(document).on('touchstart click', '.myClass', {self: this}, function (e) {

    var mylink = e.data.self.validateDomValue(this, 'attr=data-affiliate')

    if(myLink)
    {
        window.open(mylink, '_blank');
    }
});

This scripts working well for windows, mac and iPad but the problem is arising for iPhone.此脚本适用于 windows、mac 和 iPad,但问题出现在 iPhone 上。 The event is not firing for iPhone (version: 5, 6 and 7). iPhone(版本:5、6 和 7)不会触发该事件。 What was my mistake?我的错误是什么? Any of your suggestion will be appreciated.您的任何建议将不胜感激。

Oh!哦! Yes!是的! I got the point.我明白了。 I need to use css cursor:pointer .我需要使用 css cursor:pointer That works for me.这对我行得通。

if (/iP(hone|od|ad)/.test(navigator.platform)) 
{
    $(".myClass").css({"cursor":"pointer"});
}

use css cursor:pointer didn't work for me once the element I used was on 'position:fixed'.一旦我使用的元素位于“位置:固定”,使用 css cursor:pointer 对我不起作用。 I added a 'click' event listener and it solved the case.我添加了一个“点击”事件监听器,它解决了这个问题。 Once I click on the element only one of the events is fired.单击该元素后,只会触发其中一个事件。

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

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