0

I have an HTML file and I am opening it with Webkit.

I want to develop an app such that after opening it, I should be able to select some text and make it noted (say by pressing a 'Note Text' button).

When I press the button, a note image should appear on the right, but I cannot figure out the selected text position and I also have no idea about how to add a floating image on the right (maybe a div element)?

Can anyone give me a fragment of sample code about adding annotations/notes in Javascript?

2
  • 1
    What have you tried so far? Helping you is a lot easier when we can see what javascript/css/html you have already put together Commented Nov 23, 2011 at 12:28
  • In addition to what @Keith.Abramo said, have you tried googling javascript selection position and javascript floating button? Commented Nov 23, 2011 at 12:30

1 Answer 1

2

I recently used this article on Quirksmode.org to get started with identifying a user selection in Javascript. Essentially, IE differs from other browsers in what information you get about the selection: Mozilla and other browsers provide the relatively powerful Selection, while IE provides a TextRange.

If you're able to stick to Webkit-based browsers, you have significant ability to identify selected text with the Selection returned by window.getSelection().

As for adding a floating image near your selected text, you can use the anchorNode property of the Selection to find the element near to which you'll want to add your image. To do the actual positioning of the image - yes, probably in a div, I recommend learning about positioning in CSS.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.