javascript - 如何在 Chrome 扩展中创建动态选项页面

标签 javascript html google-chrome google-chrome-extension

我想创建一个包含动态创建选项的选项页面。

我正在使用我的内容脚本从网页源中提取一些数据,并且我希望该数据显示在选项页面中。我如何将该数据发送到我的选项页面?

我在内容脚本中使用了localStorage,但在选项页面中无法访问。

如果在选项页面中创建,

localStorage 可在后台页面和内容脚本中访问。但如果我在内容脚本中创建它,则无法在选项页面中访问它。

我该怎么做?

最佳答案

由于页面不共享资源,因此您需要使用:

http://code.google.com/chrome/extensions/messaging.html

引用它:

Communication between extensions and their content scripts works by using message passing. Either side can listen for messages sent from the other end, and respond on the same channel. A message can contain any valid JSON object (null, boolean, number, string, array, or object). There is a simple API for one-time requests and a more complex API that allows you to have long-lived connections for exchanging multiple messages with a shared context. It is also possible to send a message to another extension if you know its ID, which is covered in the cross-extension messages section.

关于javascript - 如何在 Chrome 扩展中创建动态选项页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8165553/

相关文章:

javascript - 将图像 append 到没有 id 或值的 td 元素

html - 如何在CSS中制作线性渐变来实现双色主体

html - 我怎样才能让css支持旧版本的浏览器

css - 如果 CSS 为 "user-select=none"的元素文本位于元素之间,则会被复制

javascript - 带十进制的 iPhone 数字键盘,适用于可编辑 DIV 上的 Web 应用程序

javascript - 如何在点击html表单的不同按钮时调用不同的servlet

c++ - 试图从 Windows API 获取 Chrome 应用程序窗口的高度和宽度?

css - 在所有网络浏览器(包括谷歌浏览器)之间保持形式和功能一致的最佳技术是什么?

javascript - 使用 superagent 和 ReactJS 将值保存在 json 文件中

html - 如何包装 primefaces 树表的标题?