Chrome extension: create div on text highlight

牧云@^-^@ 提交于 2019-12-11 05:00:20

问题


I'm looking to create a create a chrome extension which gets the currently highlighted text and creates a div just under the text, like the chrome dictionary app. Does anyone know what sort of popup this is, or how it is achieved? Thanks! Tom


回答1:


There will be two HTMLs, a popup.html - the view, and a background.html - that will be for routing, calculations, etc., the base functionality of your Extension.
As an attempt to answer your question, the way you communicate from one html to other is like:

chrome.extension.sendRequest({'action' : 'function_name', 'url' : 'ajax_url'},
    function(response) {
        callback_function(response);                 
    }); 
});

But since you want to deal with a div in page DOM, I think we use posetMessage

yourDoc.postMessage(message, 'domain_url');



回答2:


Already answered, Just some of them...

  • Get the Highlighted/Selected text
  • Selecting text in an element (akin to highlighting with your mouse)

and more for reading...

  • http://archive.plugins.jquery.com/node/7411
  • http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
  • http://www.codingforums.com/showthread.php?t=105808
  • https://www.google.es/search?q=get-user-selected-text

Good luck in your extension!



来源:https://stackoverflow.com/questions/12114185/chrome-extension-create-div-on-text-highlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!