I want my extension to listen to the event when a some text is selected (highlighted) and then dragged. just like opening new tab with dragging url to tab box. I have seen this answer this answer but it gets the text highlighted when icon is clicked but I want my some function foo() to fire automatically when text is selected and dragged. can any one help me please.
So first, you'll want to create your handler function:
function highlightHandler(e) {
// get the highlighted text
var text = document.getSelection();
// check if anything is actually highlighted
if(text !== '') {
// we've got a highlight, now do your stuff here
doStuff(text);
}
}
And then, you'll need to bind it to your document:
document.onmouseup = highlightHandler;
And finally, write your doStuff
function to do what you want it to do:
function doStuff(text) {
// do something cool
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With