Question

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.

Was it helpful?

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
}

OTHER TIPS

There is a HTML attribute which can use to get a tooltip on any element.

<p><abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>

Source: http://www.w3schools.com/tags/att_global_title.asp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top