pageAction.setTitle()

设置页面操作的标题。当用户悬停在页面操作上时,标题会显示在工具提示中。

语法

js
browser.pageAction.setTitle(
  details // 对象
)

参数

details

object

tabId

integer。要设置标题的标签页 ID。

title

stringnull。工具提示文本。

如果传入了 null,则标题将重置为在 page_action 清单键中指定的标题。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
setTitle
The title property of the details parameter can be set to null.

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support

示例

当一个标签页被更新时,在该标签页内显示页面操作,并将页面操作的标题设置为标签页的 ID:

js
browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => {
  browser.pageAction.show(tabId);
  browser.pageAction.setTitle({
    tabId,
    title: `标签页 ID:${tabId}`,
  });
});

示例扩展

备注: 该 API 基于 Chromium 的 chrome.pageAction API。本文衍生自 Chromium 代码中的 page_action.json