Results 1 to 3 of 3

Thread: If there something in the DOM or javascript to know characters selected?

  1. #1
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default If there something in the DOM or javascript to know characters selected?

    Hi folks:

    I'm working on a site for writers, and am trying to figure out a way to know the characters/words selected by a user. I'm not sure whether to include this in the javascript forum or the css forum...

    For instance, say someone is reading a page in a story online in a browser (NOT inside a textarea control, though if it's possible there, then great. I'm talking just clicking and selecting part of a web page. They click the mouse over a character, drag the mouse until a whole word is selected, and then mouseup. A word (or phrase) has just been selected, and I'd like to do some ajax-type things w/that selection. This has to be multi-browser, though I don't care about older browsers too much, and fahgedabout Mac IE 5.2.3 ;-)

    Does anyone have any idea if this is possible, and if so, how to do it? I know I can track a mousedown and mouse up event...but I've never seen any event that tracks a selection, though, of course, each browser has a 'cut/copy' capability, so the functionality is there *somewhere*. Thanks for any help. I've got a bald spot trying to figure this thing out.

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by aaava
    I'm working on a site for writers, and am trying to figure out a way to know the characters/words selected by a user. I'm not sure whether to include this in the javascript forum or the css forum...
    CSS suggests how to present a document. It has nothing to do with text selection.

    Does anyone have any idea if this is possible, and if so, how to do it?
    QuirksMode has an article on obtaining the contents of a text selection. Note that Opera's support for text selection seems to start from Opera 7, not 7.50 as the article suggests. However, if you use a click/mousedown event to run the code, Opera will return an empty string as the click will deselect the text.

    of course, each browser has a 'cut/copy' capability, so the functionality is there *somewhere*.
    That's rather flawed logic. For instance, you could copy text from a document in Opera 6, but there's no way to determine what has been selected.

    Mike
    Last edited by mwinter; 08-17-2005 at 07:15 PM.

  3. #3
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Um, thanks for the help...

    I appreciate you pointing me in the right direction. My thanks would by unrestricted if you hadn't insisted on the semantics lesson. Geez. An answer in itself is very helpful. The rest? Unnecessary.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •