Tom Kail
Tom Kail

Reputation: 11

Chrome extension: create div on text highlight

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

Upvotes: 1

Views: 1055

Answers (2)

Om Shankar
Om Shankar

Reputation: 8069

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');

Upvotes: 1

Related Questions