我想创建一个包含动态创建选项的选项页面。
我正在使用我的内容脚本从网页源中提取一些数据,并且我希望该数据显示在选项页面中。我如何将该数据发送到我的选项页面?
我在内容脚本中使用了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/