1

I want to create a in-window popup when some text is highlighted, similar to how the Google Dictionary extension works. I've already figured out how to do the highlighting portion, just can't figure out how to create the popup.

Here's the code for the highlighting:

function getSelectionText() {
    var text = "";
    if (window.getSelection) {
        text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
        text = document.selection.createRange().text;
    }
    console.log(text);
}

document.onmouseup = function() {getSelectionText()};
A. Zhang
  • 11
  • 3
  • Simply add a div element to the page. Inspect any extension that does similar thing for details. – wOxxOm May 17 '19 at 11:30
  • Possible duplicate of [How to position popover over a highlighted portion of text?](https://stackoverflow.com/questions/28246522/how-to-position-popover-over-a-highlighted-portion-of-text) – mie.ppa May 20 '19 at 18:23

0 Answers0