Firefox has a different behavior for right click from Chrome and IE. When I right click on a textfield, the caret doesn’t move. Is this a standard that only applies to firefox? This makes me frustrated.
I want the caret to move then I can know where it is by element.selectionStart and then figure out which word the user selected. All the other browsers work fine except firefox!
It there anyone who knows what’s the standard or how to workaround this? Firefox does know the exact word selected by user when the right click happens because the Check spelling works. But I don’t know.
my code:-
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
}
}
The screen shot that describes the issue:-

OK. In firefox, event.rangeOffset can be used.