views:

306

answers:

2

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).

  • 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?

+2  A: 
var canEditContent= 'contentEditable' in document.body;
bobince
+4  A: 

The best way to check for a certain feature is to actually test that feature on an element that you know should support it. I.e.

if(element.contentEditable != null)
    // than 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
Miky Dinescu
I'm not sure how I missed seeing that property.
Jason
`typeof` is an operator, not a function, so there's no need for the parentheses around the operand.
Tim Down
This works great but for someone looking to get this going on iPhone/iPad: the contentEditable property IS defined. Trouble is the OS doesn't actually support it, i.e. doesn't bring up the onscreen keyboard to let you type anything in. The only way I see at this point is regexing the UserAgent for anything iOS related.
mitjak