Checking Chrome browser validation language using jQuery or JavaScript

I am using the latest Chrome browser version 55.0.2883.87 m.

On input elements on an HTML web page, how do I dynamically retell the browser language of the Chrome browser using jQuery / JavaScript?

For example, if the page is displayed in English (USA), and the spelling check is set to English (USA), how can I pass the German language code so that the text area of ​​all input elements inside the form will check the spelling data in German, and not in english (usa) language?

Here is an example HTML text area.

<textarea cols="40" id="id_objective_details" maxlength="1000" name="objective_details" rows="10" class="kmw-disabled keymanweb-font textArea01"></textarea> 
+5
source share
1 answer

TL; DR

You can change the language with setAttribute('lang', lang) , but Chrome does not use the lang attribute to check spelling. This one will not fix the problem . Check the stream for more information.


Instead, Chrome uses custom dictionaries that must be selected by the user. (Try right-clicking the text area β†’ Spellchecking β†’ Choose language). The user must also have a dictionary installed, otherwise spell checking will not be possible.

You can try the following script and notice that changing the lang attribute will not have an effect, but changing the language manually, as mentioned above, will.

 function toLang(lang) { document.getElementById('id_objective_details').setAttribute('lang', lang); } 
 <h3>Here is some random German text</h3> <p>Hallo Welt, hallo und hallo wieder Welt.</p> <h3>Here is some random English text</h3> <p>Hello world, hello and hi again world.</p> <textarea cols="40" id="id_objective_details" maxlength="1000" name="objective_details" rows="10" class="kmw-disabled keymanweb-font textArea01" spellcheck="true"></textarea> <br> <button onclick="toLang('en')">English check</button> <button onclick="toLang('de')">German check</button> 

Perhaps you can use some external libraries, such as JavaScript SpellCheck or JQuery SpellCheck , to complete the task.

+5
source

Source: https://habr.com/ru/post/1261606/


All Articles