Reputation: 347
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.
Upvotes: 4
Views: 3127
Reputation: 14109
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
}
Upvotes: 11