I am wondering if anyone knows how I could run a function if / when the user finishes selecting text on a web page? I would like the user to be able to select the text, and after a short delay (or right away, at the moment it does not matter much), an overlay button appears next to the text, which the user can then click on, and I go back and run more of my code, which based on choice. This is for the Firefox extension.
A similar example, which I might think of, would be similar to IE, where you can select text, and then it calls "web accelerators". I'm 99% sure that I know how to actually overlay a button and get the position of the selected text, but I have no idea how to check if there is something selected without doing some endless loop that just seems like a terrible idea .
EDIT:
//In my overlay.js with the rest of my sidebar code isTextSelected: function () { var myText = cqsearch.getSelectedText(); var sidebar = document.getElementById("sidebar"); var sidebarDoc = sidebar.contentDocument || document; var curHighlightedDiv = sidebarDoc.getElementById("testDiv"); curHighlightedDiv.innerHTML = "Current text selection:" + myText; } }; //In my on firefox load function I added this document.onmouseup = cqsearch.isTextSelected;
This is what I came up with using Robert's suggestion, and it took me a while to find everything in the right place, but it works great! Now to set my button.
javascript javascript-events dom-events firefox-addon
Robert Smith Sep 16 2018-10-22T00: 00
source share