简体   繁体   English

如何检测非功能指针事件?

[英]How can I detect non-functional pointer-events?

It says here that Opera 12 doesn't support pointer-events. 这里说Opera 12不支持指针事件。 And it is true, it breaks my website. 没错,它破坏了我的网站。 The problem is that they do support the property in css, even if they don't seem to do the right thing with it. 问题在于,即使他们似乎没有对css的属性做正确的事情,他们也确实支持css中的属性。 Feature detection in the form of Modernizr is useless in this case: 在这种情况下,采用Modernizr形式的特征检测是没有用的:

>>> Modernizr.testProp('pointerEvents')
true

jQuery.browser has been removed. jQuery.browser已被删除。 What can I do to detect this corner case in my javascript code? 我该怎么做才能在我的JavaScript代码中检测到这种情况? Or to get Opera's version? 还是要获得Opera的版本?

Opera provides it's own easy way of grabbing a version. Opera提供了一种获取版本的简单方法。 If you are certain that Opera 如果您确定Opera

if (window.opera && parseInt(opera.version(), <== 12)) {
 //do the opera thing
}

will detect opera, less than or equal to 12 将检测小于或等于12的歌剧

Ok, here is my bad solution, I hope there be a better one... This is in typescript: 好的,这是我的错误解决方案,希望有更好的解决方案...这是打字稿中的内容:

    ...
    public isBadOpera(): boolean
    {
        var isOpera = Object.prototype.toString.call(window['opera']) == '[object Opera]';
        if ( isOpera )
        {
            var opera: OperaVersion = window['opera'];
            var version_string = opera.version();
            var version_re = /(\d+).(\d+)/;
            var mo = version_re.exec(version_string);
            if ( mo )
            {
                var major_version = Number(mo[1]);
                if ( major_version <= 12)
                {
                    return true;
                }
            }
        }
        return false;
    }
    ...

interface Opera {
    version():string;
}

If you only want to detect whether pointer-events are enabled you could use the navigator property according to the W3C specification : 如果只想检测是否启用了指针事件,则可以根据W3C规范使用navigator属性:

window.navigator.pointerEnabled

This gives back true for Opera 15 and above but it gives undefined for Opera 12 and below, which is what you want from what I understand. 对于Opera 15及更高版本,这是正确的,但是对于Opera 12及以下版本,则没有定义,这是您从我的理解中所想要的。

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

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