Entry
How do I find the caret position in an IE5.5+ ContentEditable DIV layer?
Apr 11th, 2002 10:39
Beiker Beikersson, Dave Clark,
In this example the cursor position is saved "onkeyup".
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>::::</title>
<script language="javascript">
var cursorPos;
function saveCursorPos(){
cursorPos=document.selection.createRange().duplicate();
}
function paste(str){
if(str) cursorPos.pasteHTML(str);
}
//-->
</script>
</head>
<body bgcolor="#ffffff">
<a href="javascript:void(0);" onclick="paste('<b>new text</b>');return
false;">test</a>
<div id="test" contenteditable onkeyup="saveCursorPos();">Beiker was a
baker once.</div>
</body>
</html>