Seeking the net brought me to Selection.addRange() is deprecated and will be removed from Chrome
But this is a bit to broad. I get this error because i have included some bootstrap into my project. Now for me "Range" means [from A to Z] or [from START to END]
Reading the above posted post tells me the trick to solve the problem is to call removeAllRanges();
befor addRange(..);
But reading removeALLranges let me suggest that several ranges or values can be added.
I tried to add removeAllRanges();
in between and it brought me several more errors because if i add a range (start) i have to add a second one (end).
Actually its not a range, its more the parameter to set in addRange
.
Here is the code in some of bootstrap generated file that causes the issue
(function() {
var iframe = document.createElement("iframe");
body.appendChild(iframe);
var iframeDoc = dom.getIframeDocument(iframe);
iframeDoc.open();
iframeDoc.write("<html><head></head><body>12</body></html>");
iframeDoc.close();
var sel = dom.getIframeWindow(iframe).getSelection();
var docEl = iframeDoc.documentElement;
var iframeBody = docEl.lastChild, textNode = iframeBody.firstChild;
// Test whether the native selection will allow a collapsed selection within a non-editable element
var r1 = iframeDoc.createRange();
r1.setStart(textNode, 1);
r1.collapse(true);
sel.addRange(r1);
collapsedNonEditableSelectionsSupported = (sel.rangeCount == 1);
sel.removeAllRanges();
// Test whether the native selection is capable of supporting multiple ranges
var r2 = r1.cloneRange();
r1.setStart(textNode, 0);
r2.setEnd(textNode, 2);
sel.addRange(r1);
sel.addRange(r2);
selectionSupportsMultipleRanges = (sel.rangeCount == 2);
// Clean up
r1.detach();
r2.detach();
body.removeChild(iframe);
})();
The problem part here is
sel.removeAllRanges();
var r2 = r1.cloneRange();
r1.setStart(textNode, 0);
r2.setEnd(textNode, 2);
sel.addRange(r1);
sel.addRange(r2); //<<============ HERE
of course i need the second range to let
selectionSupportsMultipleRanges = (sel.rangeCount == 2);
work!
How can i solve this ?
Is there a way to add a real range insead of only a start parameter ?