1

I'm looking for a way to determine if someone has selected text on a page.

There are two ways I can see to select text. Double-click on it (which automatically selects the text) or click-and-drag to select text.

  • How would I fire an event on double-click?
  • How would I fire an event when someone selects text?

jQuery is preferred

chovy
  • 72,281
  • 52
  • 227
  • 295

2 Answers2

0

for Double click see : http://www.w3schools.com/jsref/event_ondblclick.asp

for selected text see : Selected text event trigger in Javascript

Community
  • 1
  • 1
Robert
  • 386
  • 1
  • 8
0

In IE and WebKit browsers, there is a selectionchange event that fires on document nodes which sounds like what you want:

document.onselectionchange = function() {
    console.log("Selection changed!");
};

Otherwise, you'll need to detect mouse and key events and inspect the selection object when they fire.

See also:

Community
  • 1
  • 1
Tim Down
  • 318,141
  • 75
  • 454
  • 536