💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Page Actions ## Contents 1. [Manifest](pageAction.html#manifest) 2. [UI的组成部分](pageAction.html#ui) 3. [提示](pageAction.html#tips) 4. [示例](pageAction.html#examples) 5. [API reference: chrome.pageAction](pageAction.html#apiReference) 1. [Methods](pageAction.html#global-methods) 1. [hide](pageAction.html#method-hide) 2. [setIcon](pageAction.html#method-setIcon) 3. [setPopup](pageAction.html#method-setPopup) 4. [setTitle](pageAction.html#method-setTitle) 5. [show](pageAction.html#method-show) 2. [Events](pageAction.html#global-events) 1. [onClicked](pageAction.html#event-onClicked) 使用page actions把图标放置到地址栏里。page actions定义需要处理的页面的事件,但是它们不是适用于所有页面的。下面是一些page actions的示例: * 订阅该页面的RSS feed * 为页面的图片做一个幻灯片 在下面的屏幕截图中的RSS图标,提供了一个可以让用户订阅当前页面RSS Feed的page action。 ![](https://box.kancloud.cn/2015-12-28_5680aafebce23.png) 想让扩展图标总是可见,则使用[browser action](browserAction.html)。 **注意:** 打包的应用程序不能使用page actions。 ## Manifest 在 [extension manifest](manifest.html) 中用下面的方式注册你的page action: ``` { "name": "My extension", ... **"page_action": { "default_icon": "icons/foo.png", _// optional_ "default_title": "Do action", _// optional; shown in tooltip_ "default_popup": "popup.html" _// optional_ }**, ... } ``` ## UI的组成部分 同browser actions一样,page actions 可以有图标、提示信息、 弹出窗口。但没有badge,也因此,作为辅助,page actions可以有显示和消失两种状态。阅读[browser action UI](browserAction.html#ui). 可以找到图标、提示信息、 弹出窗口相关信息。 使用方法 [show()](#method-show) 和 [hide()](#method-hide) 可以显示和隐藏page action。缺省情况下page action是隐藏的。当要显示时,需要指定图标所在的标签页,图标显示后会一直可见,直到该标签页关闭或开始显示不同的URL (如:用户点击了一个连接) ## 提示 为了获得最佳的视觉效果,请遵循下列指导方针: * **要**只对少数页面使用page action; * **不要**对大多数页面使用它,如果功能需要,使用 [browser actions](browserAction.html)代替。 * **没事别总让图标出现动画,那会让人很烦。** ## 示例 你可以在[examples/api/pageAction](http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/pageAction/) 找到使用page action的简单示例,其它例子和源代码帮助查看[Samples](sample.html)。 ## API reference: chrome.pageAction ### Properties <a></a> #### getLastError chrome.extensionlastError ### Methods #### hide void chrome.pageAction.hide(, integer `tabId`) Undocumented. 隐藏page action. #### Parameters `tabId`_( optional enumerated Type array of integer )_ Undocumented. 要执行这个动作的标签ID。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function The callback _parameter_ should specify a function that looks like this: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(Type param1, Type param2) {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### setIcon void chrome.pageAction.setIcon(, object `details`) Undocumented. 为page aciton设置图标。图标可以是一个图片的路径或者是从一个canvas元素提取的像素信息.。无论是**图标路径**还是canvas的 **imageData**,这个属性必须被指定。 #### Parameters `details`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `tabId`_( optional enumerated Type array of integer )_ Undocumented. 要执行这个动作的标签ID。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `imageData`_( optional enumerated Type array of ImageData )_ Undocumented. 图片的像素信息。必须是一个ImageData 对象(例如:一个canvas元素)。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `path`_( optional enumerated Type array of string )_ Undocumented. 图片在扩展中的的相对路径。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `iconIndex`_( optional enumerated Type array of integer )_ Undocumented. **不建议。**manifest中定义的,0开始的图标数组下标。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function The callback _parameter_ should specify a function that looks like this: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(Type param1, Type param2) {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### setPopup void chrome.pageAction.setPopup(, object `details`) Undocumented. 设置一个点击page actions时显示在popup中的HTML。 #### Parameters `details`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `tabId`_( optional enumerated Type array of integer )_ Undocumented. 要设置popup的标签ID。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `popup`_( optional enumerated Type array of string )_ Undocumented. popup中显示的html文件。如果设置为空字符(''),将不显示popup。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function The callback _parameter_ should specify a function that looks like this: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(Type param1, Type param2) {...}; ``` 这个功能已经在**chromium 5.0.316.0版本**添加。如果你需要这个功能,可以通过manifest的[minimum_chrome_version](manifest.html#minimum_chrome_version)键值来确认你的扩展不会运行在早期的浏览器版本。 #### setTitle void chrome.pageAction.setTitle(, object `details`) Undocumented. 设置page action的标题,这将显示在tooltip中。 #### Parameters `details`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `tabId`_( optional enumerated Type array of integer )_ Undocumented. 要设置标题的标签ID。 `title`_( optional enumerated Type array of string )_ Undocumented. 提示信息字符串。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function The callback _parameter_ should specify a function that looks like this: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(Type param1, Type param2) {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### show void chrome.pageAction.show(, integer `tabId`) Undocumented. 显示page action,无论标签是否被选中。 #### Parameters `tabId`_( optional enumerated Type array of integer )_ Undocumented. 要执行这个动作的标签ID。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function The callback _parameter_ should specify a function that looks like this: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(Type param1, Type param2) {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. ### Events #### onClicked chrome.pageAction.onClicked.addListener(function(Tab tab) {...}); Undocumented. 当page action图标被点击的时候调用,如果page action是一个popup,这个事件将不会触发。Fi #### Parameters `tab`_( optional enumerated [Tab](tabs.html#type-Tab) array of paramType )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. ### Types <a></a> #### type name