pageAction.setTitle()
设置页面操作的标题。当用户悬停在页面操作上时,标题会显示在工具提示中。
语法
js
browser.pageAction.setTitle(
details // 对象
)
参数
details
-
object
。tabId
-
integer
。要设置标题的标签页 ID。 title
-
string
或null
。工具提示文本。如果传入了
null
,则标题将重置为在page_action
清单键中指定的标题。
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
示例
当一个标签页被更新时,在该标签页内显示页面操作,并将页面操作的标题设置为标签页的 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
。