How to **trigger a JavaScript function when someone selects a given text fragment** on a page using mouse?  

Also, is there any way to **find the position of selected text** on the page?

Update:
To be more clear, text fragment can be part of a sentence or a word or a phrase or whole a paragraph.