javascript - How to get x,y coordinates of text in paragraph (like Quora does) -


i want able x,y coordinates of end of text string has been highlighted in web browser. tried searching online similar , found quora want. code obsfucated/ compressed though can't work out did.

to see example visit question on quora (such this: http://www.quora.com/job-interviews/whats-the-craziest-thing-you-ever-said-at-an-interview-and-still-got-the-job) , highlight text in answer. little box pop-up says 'embed quote'. getting position of embedded quote want do.

i've made little demo grabs mouse position - i'd more accurate if possible. there's jsfiddle of code here: http://jsfiddle.net/binarymoon/zy8hy/

$(function(){     $(document.body).bind('mouseup', function(e){                 var selection;         if (window.getselection) {             selection = window.getselection();         } else if (document.selection) {             selection = document.selection.createrange();         }          if ( selection.tostring().length > 3 ) {             var tip = $('<div class="pointer" />');             var p =              tip.css({                 'position':'absolute',                 'left': e.pagex,                 'top': e.pagey             });             tip.appendto('.post');          }     });      $(document.body).bind('mousedown', function(e){         $('.pointer').remove();     }); }); 


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -