Disable spell-checking on HTML textfields

前端 未结 6 957
萌比男神i
萌比男神i 2020-11-28 02:27

Can I somehow disable spell-checking on HTML textfields (as seen in e.g. Safari)?

相关标签:
6条回答
  • 2020-11-28 02:35

    The following code snippet disables it for all textarea and input[type=text] elements:

    (function () {
        function disableSpellCheck() {
            let selector = 'input[type=text], textarea';
            let textFields = document.querySelectorAll(selector);
    
            textFields.forEach(
                function (field, _currentIndex, _listObj) {
                    field.spellcheck = false;
                }
            );
        }
    
        disableSpellCheck();
    })();
    
    0 讨论(0)
  • 2020-11-28 02:37

    For Grammarly you can use:

    <textarea data-gramm="false" />
    
    0 讨论(0)
  • 2020-11-28 02:40

    Update: As suggested by a commenter (additional credit to How can I disable the spell checker on text inputs on the iPhone), use this to handle all desktop and mobile browsers.

    <tag autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
    

    Original answer: Javascript cannot override user settings, so unless you use another mechanism other than textfields, this is not (or shouldn't be) possible.

    0 讨论(0)
  • 2020-11-28 02:48

    An IFrame WILL "trigger" the spell checker (if it has content-editable set to true) just as a textfield, at least in Chrome.

    0 讨论(0)
  • 2020-11-28 02:52

    Yes, use spellcheck="false", as defined by HTML5, for example:

    <textarea spellcheck="false">
        ...
    </textarea>
    
    0 讨论(0)
  • 2020-11-28 02:52

    While specifying spellcheck="false" in the < tag > will certainly disable that feature, it's handy to be able to toggle that functionality on and off as needed after the page has loaded. So here's a non-jQuery way to set the spellcheck attribute programmatically:

    0 讨论(0)
提交回复
热议问题