检测浏览器是否支持contentEditable? [英] Detect if browser supports contentEditable?

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

问题描述

这个问题,但发布的解决方案是浏览器嗅探,我正在尝试避免.

There's this question, but the solution posted is browser sniffing, which I'm trying to avoid.

我需要使我的网站与iPad以及较新的Android兼容.我在所见即所得的编辑器中一直使用旧版本的FCKEditor(现在为CK编辑器),但是在移动设备上不起作用,因此如果不支持,我想将其换成带有markdown之类的简单文本区域

I need to make my website compatible with the iPad and perhaps newer Androids. I've been using an old version of the FCKEditor (now CK Editor) for my WYSIWYG editors, but that doesn't work on mobile, so I want to swap it out for a simple textarea with something like markdown, if it's not supported.

据说它不起作用,因为移动设备倾向于不支持此contentEditable属性,这意味着单击时屏幕上的键盘不会弹出.

Supposedly it won't work because mobile devices tend not to support this contentEditable property, which means the on-screen keyboard won't pop up when you click on it.

如何检测浏览器是否支持contentEditable?有人建议我只用mydiv.contentElement === undefined之类的东西检查有问题的div,但是div(如果使用的是div)全部内置在FCK Editor中,并埋入iframe中的某个位置.

How can I detect if the browser supports contentEditable? It's been suggested that I just check the div in question with something like mydiv.contentElement === undefined or something like that, but the div (if it's using one) is all built into the FCK Editor and buried somewhere in an iframe.

没有其他方法可以检测浏览器是否总体上支持contentEditable?

Isn't there another way to detect if a browser supports contentEditable in general?

只需尝试一下:

var contentEditableSupport = typeof $('<div contenteditable="true">')[0].contentEditable !== 'undefined';

在iPad上说"true"……我认为不应该.

Says "true" on my iPad...... I don't think it should.

编辑:之所以返回字符串",是因为所有属性都是字符串....它只是在读取属性.我应该怎么做呢?

It's returning "string" because all attributes are strings.... it's just reading the attribute. How else am I supposed to do this?

推荐答案

这是我使用的测试,也是

Here is the test I use and is also used in Modernizr. It will give false positives in iOS 4 (and possibly earlier) but unfortunately it's impossible to detect in those environments.

var contentEditableSupport = "contentEditable" in document.documentElement;

这篇关于检测浏览器是否支持contentEditable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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