且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测浏览器是否支持“纯文本” contenteditable参数中的值?

更新时间:2022-11-18 09:25:21

It seems to be a webkit-only feature. The spec only allows "true", "false" and "inherit" as possible values for the attribute

A bug has been filed to add support for plaintext to the editing spec, but it's funny that the request is for "plaintext" instead of "plaintext-only".

Edit: This code can be used to detect the support. Demo:

function supportsPlainText()
{
    var d = document.createElement("div");
    try {
        d.contentEditable="PLAINtext-onLY";
    } catch(e) {
        return false;
    }
    return d.contentEditable=="plaintext-only";
}

alert(supportsPlainText());

But remember that doing browser-specific pages it's what leaded us to the IE6 problem.