Search code examples
javascriptfirefoxrollover

javascript rollover to get text


Is it possible to use javascript in order when rolling over or (clicking) a word in a web page to get that word (e.g in variable). I would like to make a firefox extension with that feature.


Solution

  • Ofcourse there is nothing such as clicking a word , as it is not an object , eventhough you can highlight a word , and yes you can get its value check this :

    https://developer.mozilla.org/en-US/docs/Web/API/Window.getSelection

    function foo() {
        var selObj = window.getSelection(); 
        alert(selObj);
        var selRange = selObj.getRangeAt(0);
        // do stuff with the range
    }