最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - how to detect if cursor text selection is visible on mobile browser? - Stack Overflow

matteradmin6PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far