简体   繁体   中英

How to do click chrome extension icon to go the option page

我正在开发一个 chrome 扩展程序,我想点击 chrome 扩展程序图标进入选项页面,有人知道怎么做吗?

In your manifest file you can keep icons for the chrome extension icons as

"browser_action": {
          "default_icon": {                    // optional
            "16": "images/icon16.png",           // optional
            "24": "images/icon24.png",           // optional
            "32": "images/icon32.png"            // optional
          }
    }

But there should be no popup.html file and also no declaration for popup.html in the browser_action key.

Now create your background scripts file and add the below code to open options page by clicking on the browser action(chrome extension icon)

    chrome.browserAction.onClicked.addListener(() => {
     chrome.runtime.openOptionsPage(() => console.log('options page opened'))
   })

Also make sure you have mentioned the options_page key in the manifest.json

You can find more details on the documention itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM