我如何捕获 Firefox 拼写检查更正事件?
我有一个文本区域。写下一些拼写错误的文本并使用右键单击 -> 后更正 该单词将被替换为拼写正确的单词。 现在,我的问题是,修正完成后我需要执行一些 javascript 代码。
如何捕获 Firefox 拼写检查更正事件? 如果只有一种使用 Firefox 附加组件的解决方案,我也很高兴知道这一点。
I have a textarea. After writing some misspelled text and using rightclick -> correction the word gets replaced with a correctly spelled word.
Now, my problem here is that i need to exectue some javascript code when the correction gets done.
How can i catch the firefox spellcheck correction event?
If there is a only a solution using a firefox Add-On i would be happy too to know that one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,Mozilla 会触发 oninput ,没有在其他地方进行测试,但应该可以在任何地方工作。
有趣的是,FF 在使用拼写校正时似乎会触发两个输入事件:它首先删除单词,然后插入新单词:
Mozilla fires oninput in this case, didn't test in others, but should work everywhere.
Interestingly enough, FF seems to fire two input events when using spelling correction: it deletes the word first, and then inserts the new one:
http://jsfiddle.net/7ssYq/
我原本打算建议
oninput
事件,例如 thg435 的答案,但我想我'首先在评论中寻找更多详细信息。如果您不需要区分拼写检查器更正和其他类型的输入(键盘、粘贴、拖放等),那么oninput
就可以很好地完成这项工作。如果您确实想要区分这些类型的输入,那么恐怕没有专门为拼写检查器更正而触发的事件。但是,大多数其他类型的输入都有事件,因此,如果您首先检查其他类型的事件,至少可以缩小输入事件为更正的可能性。请考虑以下事项:
然而,这并不是一个完美的解决方案。例如,对于不是由键盘启动的撤消/重做操作(可能还有其他一些操作),该事件仍然会触发。
I was originally going to suggest the
oninput
event, like thg435's answer, but I thought I'd fish for more details in the comments first. If you don't need to differentiate between spell checker corrections and other types of input (keyboard, paste, drag and drop, etc), thenoninput
would do the job just fine.If you do want to differentiate between those types of input, then I'm afraid there's no event that fires specifically for spell checker corrections. However, there are events for most other types of input, so you could at least narrow down the likelihood of your input event being a correction if you check for other types of event first. Consider the following:
This isn't a perfect solution, however. For instance, the event will still fire for Undo/Redo actions (and, perhaps some other actions) that aren't initiated by the keyboard.