Force spell check on a textarea in WebKit

后端 未结 3 1338
日久生厌
日久生厌 2020-12-06 02:31

I\'m creating a browser based QC/data entry app that will let people edit OCRed files, which naturally have tons of errors. Chunks of data are put in textareas so they can b

3条回答
  •  难免孤独
    2020-12-06 03:05

    Essentially you need to use the selection api to move the insertion point over each word to get Safari to highlight it. Here's an example to scan over the first thousand words...

    textarea = document.getElementById("mytextarea");
    textarea.focus();
    
    var selection = window.getSelection();
    selection.modify("move", "backward", "line");
    for (var i = 0; i < 1000; i++ ) {
        selection.modify("move", "forward", "word");
    }
    
    // Remove focus from the element, since the word under
    // the cursor won't have a misspelling marker.
    textarea.blur();
    

    This code was lifted from the WebKit Layout test suite.

提交回复
热议问题