Search code examples
javascriptselectiondetectionandroid-browser

JavaScript detect selection in Android browser


How could I detect in JavaScript in the Android Browser the event when the user selects or changes the selection of some text and elements in the HTML page using JavaScript? Android browser won't dispatch touch end is such situation? Any ideas besides establishing a timer?


Solution

  • Recent WebKit has the selectionchange event on document. I've no idea if your Android's browser is recent enough, but you could give it a try.

    document.addEventListener("selectionchange", function() {
        alert("Selection changed");
    }, false);