A
adamjroth
Hello,
I'm having trouble with IE's Range/Selection objects: when a user
click's anywhere in an element, can I create a range at that point
exactly _AND_ get the character offset? The code pasted below is a
very simple example that works in Firefox. I'd really like to know if
this can be reproduced in IE (knowing the char offset is very
important, as I need to store this information for later use).
<html>
<body>
<h1>Can this be reproduced in IE?</h1>
<div onclick="click_me( event )" style="border: 1px gray solid;
padding: 10px;">
Here is some sample text. Click anywhere in side of this div.
</div>
<script>
function click_me( event ){
var sel = window.getSelection();
var range = document.createRange();
range.setStart( sel.anchorNode, sel.anchorOffset );
var new_element = document.createElement('span');
new_element.style.color = "red";
new_element.innerHTML = '[ some text ]';
range.insertNode( new_element );
alert( "anchorOffset was: " + sel.anchorOffset );
}
</script>
</body>
</html>
Thanks in advance,
Adam
I'm having trouble with IE's Range/Selection objects: when a user
click's anywhere in an element, can I create a range at that point
exactly _AND_ get the character offset? The code pasted below is a
very simple example that works in Firefox. I'd really like to know if
this can be reproduced in IE (knowing the char offset is very
important, as I need to store this information for later use).
<html>
<body>
<h1>Can this be reproduced in IE?</h1>
<div onclick="click_me( event )" style="border: 1px gray solid;
padding: 10px;">
Here is some sample text. Click anywhere in side of this div.
</div>
<script>
function click_me( event ){
var sel = window.getSelection();
var range = document.createRange();
range.setStart( sel.anchorNode, sel.anchorOffset );
var new_element = document.createElement('span');
new_element.style.color = "red";
new_element.innerHTML = '[ some text ]';
range.insertNode( new_element );
alert( "anchorOffset was: " + sel.anchorOffset );
}
</script>
</body>
</html>
Thanks in advance,
Adam