How can I catch a firefox spelling correction event?

I have a text box. After writing the text with an error and using the correction rightclick β†’ the word is replaced with a correctly written word. Now my problem is that I need to output javascript code when the fix is ​​done.

How can I catch a firefox spelling correction event? If there is only a solution using the Firefox add-on, I would also be happy to know about it.

+4
source share
2 answers

Mozilla launches oninput in this case, has not been tested in others, but should work everywhere.

Interestingly, when using spelling correction, FF triggers two input events: first it deletes the word and then inserts a new one:

> value=[holy coww] (right click and choose "cow") > value=[holy ] > value=[holy cow] 

http://jsfiddle.net/7ssYq/

+3
source

I was originally going to offer an oninput event, for example thg435 answer , but I thought that I would fish first for more details in the comments. If you don’t need to distinguish between spelling check adjustments and other types of input (keyboard, insert, drag and drop, etc.), then oninput will do the job just fine.

If you want to distinguish between these input types, then I am afraid that there is no event that fires specifically for spell check corrections. However, there are events for most other types of input, so you could at least reduce the likelihood that your input event will become a fix if you check other types of events first. Consider the following:

 (function () { var el = document.getElementById("MyInput"), ignore = false; el.oninput = function (e) { // ignore the events that we don't need to capture if (ignore) { ignore = false; return true; } // Your code here } // IIRC, you need the following line for the `ondrop` event to fire el.ondragover = function () { return false; } // Ignore paste, drop and keypress operations el.onpaste = el.ondrop = el.onkeypress = setIgnore; function setIgnore (e) { ignore = true; } })(); 

This is not an ideal solution. For example, the event will still trigger Undo / Redo actions (and possibly some other actions) that are not triggered by the keyboard.

+1
source

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


All Articles