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.
Asked
Active
Viewed 95 times
-1
-
Assuming you can use jQuery, you probably want something like this: http://stackoverflow.com/questions/12434232/display-alert-when-mouse-hovers-over-word-in-text?rq=1 – Charlie74 Dec 14 '13 at 14:31
-
@Charlie74 I think he wants a way to achieve this without having control over the page itself. e.g. an extension that would allow this to be done on any page. As far as I know, that would be difficult to achieve reliably, if at all. – DBS Dec 14 '13 at 14:36
-
@DBS agh yes, I think you're correct. After reading again, I see the goal is an extension, which would make this page independent. – Charlie74 Dec 14 '13 at 14:38
-
Yes it is actually about independent pages on the web, so an extension is the way. – unicorn Dec 14 '13 at 20:35
2 Answers
0
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
}

ProllyGeek
- 15,517
- 9
- 53
- 72
-1
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>

Zero Fiber
- 4,417
- 2
- 23
- 34
-
So many things wrong ... dangling abbr close tag, link to w3schools, and you didn't actually answer the OP's question! – Jack Dec 14 '13 at 14:52