faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

73 of 76 people (96%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I access the user's selection (highlighted text) in a document?
If you DO overwrite, how then do you access the entire changed source?

Apr 8th, 2000 04:25
Martin Honnen, John Marc,


NN4 has
  var text = document.getSelection();
to read the selected text.
IE4+ has a sophisticated 
  document.selection
object which allows to create a range to manipulate the selection. If 
you just want to read the selected text use
  var text = document.selection.createRange().text;
If you for instance what to overwrite it use e.g.
  document.selection.createRange().text = 'Kibology';
At the time of writing it seems that NN6 aims to at least provide
  document.getSelection()
as NN4 does but it doesn't so far work in NN6PR1 preview release.