Maps cross browser?

I am creating a WYSIWYG editor and I need to know how to work with the caret. There seems to be no obvious way to make this cross-platform.

I just need the syntax. Do not direct me to the Mozilla developer page; I did not find this particularly useful. I use content edited by div.

the source I was looking at

+2
source share
1 answer

try it

function doGetCaretPosition (oField) { // Initialize var iCaretPos = 0; // IE Support if (document.selection) { // Set focus on the element oField.focus (); // To get cursor position, get empty selection range var oSel = document.selection.createRange (); // Move selection start to 0 position oSel.moveStart ('character', -oField.value.length); // The caret position is selection length iCaretPos = oSel.text.length; } // Firefox support else if (oField.selectionStart || oField.selectionStart == '0') iCaretPos = oField.selectionStart; // Return results return (iCaretPos); } 
+9
source

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


All Articles