Tigran Tigran Tigran Tigran - 1 year ago 256
Javascript Question

textRange MoveToPoint() IE

Have a problem with moveToPoint() method of textRange IE11;

Seems like it dosen't work if pointed node wasn't in first screen;

document.addEventListener( "click", function(e) {
var x = e.clientX;
var y = e.clientY;
var range = document.body.createTextRange();
range.moveToPoint(x, y);

This code grab words from click point, but it wokrs normal only if we clicking in node's that were on first scroll.

If we scroll little bit down to the node that wasnt in first scroll, we will catch the exeception.

Does anybody know how to handle this situation correctly?

Answer Source

I can confirm that such a bug exists in IE11. You can find details here in comments: http://generatedcontent.org/post/69213745095/ie11review-part1

Possible solution (after you create a range):


Now you have the first word selected. You have to check now if the selected word fits your mouse click position using TextRange properties boundingHeight, boundingWidth, boundingLeft and boundingTop. If it doesn't, you move in cycle to the next word:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download