Playing with ifames in designMode = "on"
Here is the code snippet:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function start(){
document.getElementById("testframe").contentWindow.document.designMode = "on";
}
function curpos(){
var frame = document.getElementById("testframe").contentWindow;
var sel = frame.getSelection();
var range = sel.getRangeAt(0);
var selStart = range.startOffset;
alert(selStart);
}
</script>
</head>
<body onload="start()">
<iframe width="500" height="200" id="testframe" style="cursor:text"></iframe>
<hr />
<button onclick="curpos()">CurPos</button>
</body>
</html>
Code returns the correct position IF the text inside consists a single line.
Problem is multiline content. If you put something like:
Code:
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
and put the cursor at a random position, and click the CurPos button, it returns sometimes the position of the cursor in that particular line, or sometimes some random number.
How can I get the cursor position at whole text?
Thanks.