Chrome extension double click on a word

后端 未结 1 1675
囚心锁ツ
囚心锁ツ 2021-01-11 12:03

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 Dictio

相关标签:
1条回答
  • 2021-01-11 12:31

    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);
    
    0 讨论(0)
提交回复
热议问题