how I can change default icon in chrome extension?

牧云@^-^@ 提交于 2020-12-24 07:14:34

问题


Here I am working with chrome extension development.

my manifest.json page as show

{
"name": "DemoExtension",
  "version": "1.0",
  "description": "Official addon from demeo",
  "browser_action": {
    "default_icon": "star-on.png",
    "popup": "shopcmp.htm"  
  },
  "permissions": [
    "tabs"    
  ],
  "background_page": "background.html"   
}

Here I want to change my default icon image at runtime.


回答1:


If you want to change the browser action default icon, just change

"browser_action": {
  "default_icon": "star-on.png", //<--this line: change "star-on.png" to the icon you want
  "popup": "shopcmp.htm"  
},

That line indicates the default icon on first load of the extension.
To change the icon in code, call chrome.browserAction.setIcon(details).

If you want to change the extension icon (the icons that shows during installation, in the Chrome Web Store, in the extension management page, and as a favicon), add an icons property to your manifest.json file.




回答2:


To change the default chrome extension pragmatically you can do:

chrome.browserAction.setIcon({path:"my-icon.png"});



回答3:


if you want every page has its own icon status, use chrome.pageAction.



来源:https://stackoverflow.com/questions/6939974/how-i-can-change-default-icon-in-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!