Address bar button 编辑

Commonly referred to as a page action button, this user interface option is a button added to the browser address bar. Users click the button to interact with extensions.

Page actions and browser actions

The address bar button (or page action) is similiar to the toolbar button (or browser action).

The differences are:

  • The button’s location:
    • The page action is displayed inside the browser address bar.
    • The browser action is displayed outside the address bar, in the browser toolbar.
  • The button’s visibility:
    • The page action is hidden by default (although this default can be changed via the show_matches and hide_matches manifest key properties), and you call pageAction.show() and pageAction.hide() to show or hide it in specific tabs.
    • The browser action is always displayed.

Use a page action when the action relates to the current page. Use a browser action when the action relates to the browser as a whole or to many pages. For example:

TypeBookmarks actionContent actionTabs operation
page actionBookmark this pageReddit enhancementSend tab
browser actionShow all bookmarksEnable ad-blockingSync all open tabs

Specifying the page action

You define the page action's properties using the page_action key in manifest.json:

"page_action": {
  "browser_style": true,
  "default_icon": {
    "19": "button/geo-19.png",
    "38": "button/geo-38.png"
  },
  "default_title": "Whereami?"
}

The only mandatory key is default_icon.

There are two ways to specify a page action: with or without a popup.

  • Without a popup: When the user clicks the button, an event is dispatched to the extension, which the extension listens for using pageAction.onClicked:
  • browser.pageAction.onClicked.addListener(handleClick);
  • With a popup: the click event is not dispatched. Instead, the popup appears when the user clicks the button. The user then interacts with the popup. When the user clicks outside of the popup, it closes automatically. See the Popup article for more details on creating and managing popups.

Note that your extension can have just one page action.

You can change any of the page action properties programmatically using the pageAction API.

Icons

For details on how to create icons to use with your page action, see Iconography in the Photon Design System documentation.

Examples

The webextensions-examples repository on GitHub includes the chill-out example which implements a page action without a popup.

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

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

发布评论

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

词条统计

浏览:121 次

字数:5394

最后编辑:7年前

编辑次数:0 次

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