如何仅在单一情况下打开chrome扩展弹出窗口?

时间:2012-03-06 23:03:48

标签: javascript json google-chrome google-chrome-extension

我试图在我的工具栏上制作镀铬扩展程序,点击后,会将当前页面转换为该页面的Google缓存版本。如果我已经在页面的Google缓存中,我想打开一个小弹出窗口,"您已经在此页面的Google缓存版本上了!"

这是我得到的:

的manifest.json:

{
  "name": "gCache",
  "version": "1.1.5",
  "description": "View the Google Cache of a page",
  "background_page": "redirect.html",

  "browser_action": {
    "default_icon": "icon.png",
    "default_text": "Google Cache version of this page"
  },

  "permissions": [
    "tabs"
  ]
}

将redirect.html:

<script>

chrome.browserAction.onClicked.addListener(function(tab) {
    if (tab.url.substring(0, 38) == "http://webcache.googleusercontent.com/")
        //Popup saying user is already on a webcache page
    else if(tab.url.substring(0, 5) == "http:")
        chrome.tabs.update(tab.id, { url: 'http://webcache.googleusercontent.com/search?q=cache:' + tab.url.substr(7) });
    else if(tab.url.substring(0,6) == "https:")
        chrome.tabs.update(tab.id, { url: 'http://webcache.googleusercontent.com/search?q=cache:' + tab.url.substr(8) });

});

</script>

感谢您的阅读和帮助!

1 个答案:

答案 0 :(得分:0)

您无法在打开弹出窗口时混合和匹配browserAction onClick个事件。您可能希望改为使用Desktop Notifications API