Should a right-click on a text field move a caret in the same way as a left-click?

Firefox has a different right-click behavior from Chrome and IE. When I right-click on a text box, the carriage does not move. Is this a standard that applies only to firefox? It makes me sad.

I want the carriage to move, then I can know where it is on element.selectionStart , and then find out which word the user has selected. All other browsers work fine except firefox!

There, who knows what standard or how to manage it? Firefox knows the exact word that the user selected when right-clicking because spell checking works. But I do not know.

my code is: -

 function onContextMenu(evt){ var el = evt.getTarget(), selStart, r, ln = el.value.length; // Get the location of the cursor if (el.createTextRange) { // IE r = document.selection.createRange().duplicate(); r.moveEnd('textedit'); selStart = (r.text == '') ? ln : ln - r.text.length; } else { // All compliant browsers selStart = el.selectionStart; //works fine for chrome } } 

Screenshot that describes the problem: -

enter image description here

+4
source share
1 answer

OK Firefox can use event.rangeOffset.

+1
source

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


All Articles