admin管理员组

文章数量:1435823

I'm trying to add update the jQuery Terminal cursor position when text selection cursor is visible. This is my code:

function update_mobile_cursor() {
    if (is_mobile) {
        var selection = document.getSelection();
        console.log(selection);
        if (selection.anchorNode === selection.focusNode) {
            var range = selection.getRangeAt(0);
            console.log(range);
            self.position(range.endOffset);
        }
    }
}

But both selection and range exists even when the selection cursor is not visible. When I type something, the endOffset points into the last typed character.

Is there a way to detect the visibility of the selection cursor on a mobile Browser?

I have a testing webpage: .php when You press backspace it jumps to the beginning.

NOTE: that the function don't trigger when text selection is changed, I've asked about it here: Listen to cursor change on mobile browser

I test this with Chromium based Brave.

本文标签: javascripthow to detect if cursor text selection is visible on mobile browserStack Overflow