Options page 编辑

An Options page enables you to define preferences for your extension that your users can change. Users can access the options page for an extension from the browser's add-ons manager:

The way users access the page, and the way it's integrated into the browser's user interface, will vary from one browser to another.

You can open the page programmatically by calling runtime.openOptionsPage().

Options pages have a Content Security Policy that restricts the sources from which they can load resources, and disallows some unsafe practices such as the use of eval(). See Content Security Policy for more details.

Specifying the options page

To create an options page, write an HTML file defining the page. This page can include CSS and JavaScript files, like a normal web page. This page, from the favourite-colour example, includes a JavaScript file:

<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8"/>
  </head>

  <body>
    <form>
      <label>Favourite colour</label>
      <input type="text" id="colour"/>
      <button type="submit">Save</button>
    </form>
    <script src="options.js"></script>
  </body>
</html>

JavaScript running in the page can use all the WebExtension APIs that the add-on has permissions for. In particular, you can use the storage API to persist preferences.

Package the page's files in your extension.

You also need to include the options_ui key in your manifest.json file, giving it the URL to the page.

"options_ui": {
  "page": "options.html",
  "browser_style": true
},

Note: Google Chrome and Opera use chrome_style instead of browser_style, so if you wish to support them, you need to add both keys.

See the options_ui page for sharing options between your options page and background or content scripts.

Options content design

For details on how to design your options content to match the style of Firefox, see the Photon Design System and browser styles documentation.

Examples

The webextensions-examples repository on GitHub includes the favourite-colour example which implements options page features.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:120 次

字数:4339

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文