如何通过JavaScript检测对contentEditable的支持? [英] How do I detect support for contentEditable via JavaScript?

查看:105
本文介绍了如何通过JavaScript检测对contentEditable的支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这个几天现在,到目前为止,我能找到的最好的是检查下面的列表。我真的不喜欢检查基于用户代理的支持,特别是因为它可以欺骗。我也听说过至少有一个实例,其中下面的列表不正确(如下所示)。

I've been searching for this for a couple of days now and so far, the best I can come up with is checking the list below. I really don't like to check for support based on User-Agent, especially since it can be spoofed. I've also heard of at least one instance where the list below is incorrect (noted below).


  • 是Internet Explorer吗? >
  • 是WebKit吗?
  • Is Internet Explorer?
  • Is WebKit? (But I've read that mobile Safari doesn't support it)
  • Is Opera?
  • Is Gecko and version >= 1.9? (meaning Firefox 3 or later)

有更好的方法,或者这是测试支持的唯一方法?

Is there a better method based on testing for support directly via JavaScript, or is this pretty much the only way to test for support?

推荐答案

检查某个特性的最好方法是

The best way to check for a certain feature is to actually test for that feature on an element that you know should support it, like this:

if(element.contentEditable != null)
    // then it's supported

>

or

if(typeof(element.contentEditable) != 'undefined')
   // same thing.. but with typeof you can be more specific about the type of property you need to find

这篇关于如何通过JavaScript检测对contentEditable的支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆