Chrome扩展程序双击一个字 [英] Chrome extension double click on a word
问题描述
我想知道如何在用户双击他们正在访问的页面上的任何单词时(从内容脚本)调用一个函数。类似于 Google字典扩展程序。我检查了扩展中的代码,但它没有缩进(编译/最小化),所以我决定在这里提出这个问题。一小段代码会很好。提前致谢:)
I would like to know how to call a function once the user double-clicks on any word on the page they are visiting (from a content script). Something similar to Google Dictionary extension. I have inspected the codes in the extension but it was not indented (compiled/minimized) so I've decided to ask this question here. A snippet of codes would be good. Thanks in advance :)
推荐答案
我怀疑Google会在页面上添加一个EventListener来注册双击,然后获取文本这是自动选择的。
I suspect Google adds an EventListener to the page to register a double click, and then gets the text that was automatically selected.
http ://developer.mozilla.org/en/DOM/element.addEventListener
http://developer.mozilla.org/en/DOM/window.getSelection
f=function(){
console.log(window.getSelection().toString());
}
document.body.addEventListener('dblclick',f);
这篇关于Chrome扩展程序双击一个字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!