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.
Asked
Active
Viewed 2,998 times
1 Answers
11
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
}

Bluefire
- 13,519
- 24
- 74
- 118
-
Clean code and well commented, just what I was looking for. – brooklynsweb Mar 02 '15 at 19:13