开发者

SurroundContents on a range spanning multiple tags (getRangeAt problem?)

开发者 https://www.devze.com 2022-12-09 02:53 出处:网络
I have a script that (I think) needs to use surroundContents to wrap the selection area. Doing so allows me to append something, and then reassign the range as the selection.

I have a script that (I think) needs to use surroundContents to wrap the selection area. Doing so allows me to append something, and then reassign the range as the selection.

I believe I've narrowed the problem down to a misuse of getRangeAt, but I'm not quite sure how to correct it.

Here's the brief bit of code:

        function getRangeObject(selectionObject) {
        // Moz
        if (selectionObject.getRangeAt) {
            return selectionObject.getRangeAt(0);
     开发者_如何学JAVA   }

And here's line 89 where it throws an error at me:

rangeObject.surroundContents(newNode);

And of course, here's the error:

Error: uncaught exception: [Exception... "The boundary-points of a range does not meet specific requirements." code: "1" nsresult: "0x805c0001 (NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR)" location: "http://www.latentmotion.com/insertNode/index26.html Line: 89"]

If it's helpful to see the whole thing, you can view the script (so far) here: http://www.latentmotion.com/insertNode/index26.html

And the text selection helper that I was going off of was quirksmode - which doesn't detail the use of multiple ranges, located here.

Thanks in advance for your help.


I think the error message describes the problem well. This section of the DOM Range spec describes what leads to an exception being thrown by a Range when using surroundContents.

0

精彩评论

暂无评论...
验证码 换一张
取 消