Chrome扩展程序:在文本突出显示上创建div [英] Chrome extension: create div on text highlight

查看:104
本文介绍了Chrome扩展程序:在文本突出显示上创建div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找创建一个chrome扩展程序,该扩展程序获取当前突出显示的文本并在该文本下方创建一个div,例如chrome字典应用程序.有人知道这是哪种弹出窗口,或如何实现吗? 谢谢! 汤姆

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

推荐答案

将有两个HTMLs,一个popup.html-视图,一个background.html-用于路由,计算等,扩展程序的基本功能.
为了回答您的问题,您从一个html到另一个html的通信方式如下:

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

但是由于您要处理页面DOM中的div,所以我认为我们使用了posetMessage

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

yourDoc.postMessage(message, 'domain_url');

这篇关于Chrome扩展程序:在文本突出显示上创建div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆