Probably attach an event listener to onmouseup and check if the currently selected text is inside the element, and if so, show the pop-up window, filling it with the selected text. Most of them are pretty simple, but the part where you check to see if the text in the target element is completely contained will be a bit complicated - mainly because you will be different code for different browsers. For older versions of IE, see document.selection and document.selection.createRange() . For others (including IE9), see window.getSelection() .
source share