[removed] error 800a025e using range selector

后端 未结 3 1527
栀梦
栀梦 2021-01-07 22:36

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

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 23:10

    I got this error when trying to window.getSelection().removeAllRanges(); and there was no selection. One workaround is to check if there is a selection first:

    if (window.getSelection().getRangeAt(0).getClientRects.length > 0) {
        window.getSelection().removeAllRanges();
    }
    

    Also, this question is a duplicate of Could not complete the operation due to error 800a025e, but I couldn't mark it as such because the other question doesn't have an accepted answers.

提交回复
热议问题