Show popup with highlighted color after selecting text and clicking with mouse

http://msdn.microsoft.com/en-us/vcsharp/aa336760#WhereSimple1

On this page, when part of the code is highlighted and the mouse pops out, a pop-up window will appear with the code, this is javascript. how to code it?

+4
source share
1 answer

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() .

+2
source

All Articles