onhighlighttext

I suggest to add a new event in the Javascript DOM, namely onhighlighttext.

Example :

document.addEventListener("onhighlighttext", function(){
  alert("wow you highlighted me sir!");
});

Actually we can do this with getSelection by onmouseup or keyup , but it ends up with a syntax that is not neat and hard to read.

var t = "";
function gText(e) {
    t = (document.all) ? document.selection.createRange().text : document.getSelection();
    document.getElementById('input').value = t;
}

document.onmouseup = gText;
if (!document.all) document.captureEvents(Event.MOUSEUP);

Besides that we can use selectionchange, but selectionchange as the latter fires so many events (up to the chars selected), you have to wait some arbitrary period to get the final selection.

I can't find any ideas and proposals about this.

This discourse is for the JavaScript language, which doesn’t include the DOM at all. Try https://discourse.wicg.io

1 Like

Thanks sir, i'll try :D