如何在Chrome扩展中创建动态选项页面 [英] How to create a dynamic options page in chrome extension

查看:120
本文介绍了如何在Chrome扩展中创建动态选项页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我使用我的内容脚本从网页源中提取一些数据,并且我想要这些数据将显示在选项页面中。我怎么能将这些数据发送到我的选项页面?



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



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



我该如何做到这一点?


我刚刚提取了我的内容脚本中的数据,然后,我与我的background_page并在消息传递的帮助下将数据发送到background_page。在我的background_page中,我将数据存储在可在我的选项页面中访问的localStorage中。有点棘手,但成功工作。


I want to create an options page with dynamically created options.

I am extracting some data from a web page' source using my content script and I want that data to be displayed in the options page. How could I send that data to my options page?

I have used localStorage in content script but that is not accessible in options page.

localStorage is accessible in background page and content script if created in options page. But if I am creating it in content script, it is not accessible in options page.

How can I do this?

解决方案

I have got the solution.

I just extracted the data in my content script,then, I communicated with my background_page and sent the data to the background_page with the help of Message Passing. In my background_page I stored the data in the localStorage which is accessible in my Options page. Little tricky but working successfully.

这篇关于如何在Chrome扩展中创建动态选项页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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