mardi 11 septembre 2018

Why window.getSelection().toString() cannot get any result on IE and firefox?

Browser vision

IE8+

Firefox 62.0

chrome 69.0.3497.92

Code

function getCursortPosition (Dom) {
var cursorIndex= 0;
var word;

 if (document.selection) {
        Dom.focus ();
        var range= document.selection.createRange();
        range.moveStart ('character', -Dom.value.length);
        cursorIndex= range.text.length;
        word = range.text;
    }else if (Dom.selectionStart || Dom.selectionStart==0) {
        cursorIndex= Dom.selectionStart;
        word = window.getSelection().toString();
    }
    search.word = word;
    search.currentSelect = cursorIndex;
};

Question

Baes on MDN web docs

"A Selection object. When cast to string, either by appending an empty string ("") or using Selection.toString(), this object returns the text selected."

But it's failure to get Selection.toString() result on IE,Firefox and only chrome works.




Aucun commentaire:

Enregistrer un commentaire