Anyone know if there is a trigger for this or variable I can poll to check if something is currently highlighted on the page?
Building a Chrome extension where I need to have a script be activated when the user highlights text
Asked
Active
Viewed 28 times
1 Answers
0
You can check if a "mouseup"-event was fired and then get the currently selected text:
document.onmouseup = ()=>{
selection = window.getSelection().toString()
if(selection){
alert(`"${selection}" is highlighted`)
}
}
Select me!

benS
- 71
- 1
- 7