2015-04-28 388 views
0

我是新開發鉻擴展,並希望從一些簡單的代碼開始。我試圖在用戶點擊圖標時更改徽章文本。但是,這似乎並不奏效。任何人都可以建議我在這裏做錯了什麼?單擊圖標時如何更改Chrome擴展徽章文本?

的manifest.json

{ 
    "name": "Hello World", 
    "description": "Just displays hello world", 
    "version": "1.2", 
    "manifest_version": 2, 
    "background": 
    { 
     "scripts": ["background.js"], 
     "persistent": false 
    }, 
    "browser_action": 
    { 
     "name": "Click to display", 
     "default_popup": "popup.html" 

    } 

} 

background.js

function updatebadge() 
{ 
chrome.browserAction.setBadgeText({text: "Hello!"});  
}; 

chrome.browserAction.onClicked.addListener(updatebadge); 

popup.html

<body> 
    Hello, World! 
</body> 

回答