Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

html - Setting spellcheck language in Google Chrome

I'm trying to create a simple editable field (for posting) while combining a spellcheck:

<div contenteditable="contenteditable" spellcheck="spellcheck" lang="en">text</div>

(http://www.wufoo.com/html5/attributes/17-spellcheck.html)

It works, but on Google Chrome, the spellchecker doesn't detect the language. (despite the specified @lang attribute)

The "bug" was fixed in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=338427

But I can't find anything about Google Chrome's implementation of this. Is there a way to notify the spellchecker about the expected language in an HTML5 field? Maybe something in the <head> like charset, meta lang, etc?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The spellcheck attribute is not implemented in all browsers yet. If it is, there are some bugs need to be fixed.

According to W3Schools:... (Update: now supported by "all" browsers.)

When I visit the link you mentioned above (in Chrome 22) there are some bugs. The spellchecker says on "key" it's mispelled, and double clicking on some words makes it indicated as misspelled, too. I had Hungarian selected as spellchecking language.

NOTE: The language can be changed by right-clicking on the input, but you need to reload the page.

Also there are some browsers where spellchecking is turned of in the settings.

As I saw in the comments, bwitkowicz mentioned a solution with JS.

function updateStatus() {
    console.log("updating");
    $("#spellStatus").text( String( $("#textContent").attr("spellcheck") ) );
    $("#editStatus").text(  String( $("#textContent").attr("contentEditable") ) );    
}

$(function() {
    updateStatus();
    
    $("#spell").ready(function() {
        console.log("spell");
        $("#textContent").attr( "spellcheck", function(ix,old) {
            old = old === "false" ? false : true;
            console.log("setting " + (!old));
            return old;
        });
    });
    $("#edit").ready(function() {
        console.log("edit");
        $("#textContent").attr( "contentEditable", function(ix,old) {
            old = old === "false" ? true : false;
            console.log("setting " + (!old));
            return !old;
        });
    });
    
    $("#spell, #edit").ready(updateStatus);
    
});
#spell, #edit, #spellStatus, #editStatus {
     display: none;   
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div><button id="spell">Toggle Spellcheck</button><span id="spellStatus"></span></div>
<div><button id="edit">Toggle Editable</button><span id="editStatus"></span></div>
<div id="textContent" style="padding: 5px; border: 1px solid black;">
Here is some texxt with spellung erreurs. Also you have to click inside the div to chekc erorrrrs.
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...