代码之家  ›  专栏  ›  技术社区  ›  andrewk

chrome browserAction到pageAction

  •  1
  • andrewk  · 技术社区  · 15 年前

    这在browserAction中效果很好。。 但当我切换到页面动作时。。即使是图标也不会出现

    背景.html

    <html>
        <head>
        <script>
          // Called when the user clicks on the browser action.
          chrome.browserAction.onClicked.addListener(function(tab) {
            chrome.tabs.create({'url':'http://google.com/search?q=site:'+window.location.host});
          });
    
        </script>
        </head>
        </html>
    

    清单.json

    {
      "name": "linkcheck",
      "description": "check link.",
      "version": "1.1.1",
      "
    
    background_page": "background.html",
      "permissions": ["tabs", "http://*/*","https://*/*"],
      "browser_action": {
        "name": "linkcheck",
        "default_icon": "icon.png"
      },
      "icons": {
          "128": "icon128.png",
          "48": "icon48.png"             
       },  
    
      "content_scripts": [
        {
          "matches": ["https://www.google.com/*"],
          "js": ["myscript.js"],
          "run_at": "document_end"
        }
      ]
    }
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Mohamed Mansour    15 年前

    对于pageAction,您需要输入另一个清单 property

    {
      "name": "My extension",
      ...
      "page_action": {
        "default_icon": "icons/foo.png", // required
        "default_title": "Do action",    // optional; shown in tooltip
        "default_popup": "popup.html"    // optional
      },
      ...
    }
    

    那你要么 hide show .

    chrome.pageAction.show(integer tabId)