Page Action類型的Google Chrome瀏覽器擴展程序,通常也會有一個圖標,但這個圖標位於Chrome瀏覽器的地址欄內右端。而且這個圖標並非始終出現,而是當某指定的頁面打開時才會出現。也就是說,這個圖標與當前打開的頁面有關,只有打開了指定的頁面才會顯示該圖標,對該頁面執行對應的操作。
定義Page Action類型的Google Chrome擴展程序,首先要在manifest.json文件中注冊如下:
{
...
"page_action": {
"default_icon": { // optional
"19": "images/icon19.png", // optional
"38": "images/icon38.png" // optional
},
"default_title": "Google Mail", // optional; shown in tooltip
"default_popup": "popup.html" // optional
},
...
}
對於Page Action類型的Google Chrome擴展程序,其圖標、提示、彈出框都類似於Browser Action。
Page Action沒有徽章,但是有顯示或隱藏的變化。默認Page Action是隱藏的,必須指定打開什么樣的tab時顯示Page Action的圖標。
控制Page Action的圖標顯示使用chrome.pageAction.show(integer tabId)方法。
控制Page Action的圖標隱藏使用chrome.pageAction.hide(integer tabId)方法。
點擊Page Action的圖標綁定事件使用chrome.pageAction.onClicked.addListener(function (tab) {…})方法。