Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: error 800a025e using range selector

I'm executing these simple rows of javascript in latest ie 11, just to select all content of a div

Here a screenshot from ie11 dev tool

Code and error - screenshot

Like you can see, IE alter me saying: "unable to complete the operation due to error 800a025e".

I'm not able to understand the nature, the source, of the problem, and no others stack overflow questions I read give me a clear answer.

This is full code of my selectText jQuery "personal" extension

jQuery.fn.selectText = function(){
    var doc = document;
    var element = this[0];
    // console.log(this, element);
    if (typeof element == 'undefined') {
        return;
    }
    if (doc.body.createTextRange) {
        var range = document.body.createTextRange();
        range.moveToElementText(element);
        range.select();
    } else if (window.getSelection) {
        var selection = window.getSelection();        
        var range = document.createRange();
        range.selectNodeContents(element);
        selection.removeAllRanges();
        selection.addRange(range);
    }
};

Element in this case is a

[Object HTMLTableElement]

Edit 1: with a little mod:

var range = document.body.createTextRange();
var retval = range.moveToElementText(element);
console.log (retval);
range.select();

I'm able to say you retval is undefined. This code work on ff without problems, so element selector is fine. jQuery version is 1.11

like image 875
realtebo Avatar asked Apr 07 '14 13:04

realtebo


1 Answers

I resolved using this trick:

I wrapped the html table with a DIV

I use the same code, as is, with no changes, against the DIV, instead of using for selecting only the table.

It's working.

Probably html table is not a selectable text for IE

like image 191
realtebo Avatar answered Sep 22 '22 10:09

realtebo