1

Let's say a user selects (with his/her mouse) the first line of a paragraph. Later, he/she selects another line farther down the page. Is there a way to keep the previously selected text (in addition to the newly selected text) highlighted? How could I go about achieving this?

Many thanks in advance.

lamuchacho
  • 15
  • 1
  • 5
  • You could produce something similar that looks like it, but it won't be *selected* by the browser. – alex Feb 10 '12 at 05:19

2 Answers2

2

Yes, you can do this with a combination of checking the mouseDown/mouseUp event, and document.selection/getSelection.

The general logic is this:

  1. On mouse down, save the current value of document.selection into an array, if there was a selection
  2. On mouse up, check to see if there is anything selected. If so, add it to the same array
  3. Redo the selection manually by adding every range in that array

It would behoove you to use something to handle cross-browser implementation. Check out this guy's snippet

Jordan
  • 31,971
  • 6
  • 56
  • 67
0

I do not believe so. The highlighting is not server-side/localhost controlled; It's a function usually built into the operating system that allows highlighting of text, or sometimes it's a function in the web browser.

Sorry I couldn't be more helpful or give you a solution that allows you to do this. Only other way I know is to use IFrames, because they act as oppositions from the primary page's highlighted elements/text.

Kinz
  • 310
  • 1
  • 2
  • 14