# 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。

想讓擴展圖標總是可見,則使用[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
- 基礎文檔
- 綜述
- 調試
- 格式:Manifest文件
- 模式匹配
- 改變瀏覽器外觀
- Browser Actions
- Context Menus
- 桌面通知
- Omnibox
- Override替代頁
- Page Actions
- 主題
- 與瀏覽器交互
- 書簽
- Cookies
- chrome.devtools.* APIs
- Events
- chrome.history
- Management
- 標簽
- 視窗
- 實現擴展
- 無障礙性(a11y)
- 背景頁
- Content Scripts
- 跨域 XMLHttpRequest 請求
- 國際化 (i18n)
- 消息傳遞
- Optional Permissions
- NPAPI 插件
- 完成并發布應用
- 自動升級
- 托管
- 打包
- 規范和協議
- 應用設計規范
- 開發人員協議
- 免責聲明