2014-10-30 93 views
-1

我是Chrome扩展的新手。我创建了一个简单的Chrome扩展来显示最新的新闻更新,它工作正常。现在,我怀疑是什么,当我发布新帖子时,Chrome扩展图标应该显示1的通知。这意味着新帖子已更新通知。你可以看到CNN新闻的Chrome扩展。与CNN通知的Chrome扩展程序

是否有任何可能的方式来显示通知。

我manifest.json的代码,

{ 
    "name": "my name", 
    "description": "my desc", 
    "browser_action": { 
     "default_icon": { 
      "19": "icons/icon19.png" 
      }, 
     "icons": { "16": "icons/icon16.png","48": "icons/icon48.png", "128": "icons/icon128.png" },  
     "default_title": "my name", 
     "default_popup": "popup.html" 
    }, 
    "manifest_version": 2, 
    "update_url": "http://clients2.google.com/service/update2/crx", 
    "content_security_policy": "script-src 'self' https://www.google.com; object-src 'self'", 
    "version": "0.1" 
} 

我Popup.html

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>my name</title> 
    <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
    <script type="text/javascript" src="script.js"></script> 
</head> 

<body> 

    <div id="feed"></div> 

</body> 
</html> 

我的script.js的代码是

google.load("feeds", "1"); 

    function initialize() { 
     var feed = new google.feeds.Feed("http://feeds.feedburner.com/myname/"); 
     feed.setNumEntries(10); 
     var count = 1; 
     feed.load(function(result) { 
     if (!result.error) { 
      var container = document.getElementById("feed"); 
      var html = ""; 
      for (var i = 0; i < result.feed.entries.length; i++) { 
      var entry = result.feed.entries[i]; 
      html = "<div class='feeds'><h5>" + count++ + ". <a href='" + entry.link + "'>" + entry.title + "</a></h5></div>"; 
      var div = document.createElement("div"); 
      div.innerHTML = html; 
      container.appendChild(div);    
      } 
      document.write(html); 
     } 
     }); 
    } 
    google.setOnLoadCallback(initialize); 
+1

你能提供你试过的代码的例子吗? – biscuit314 2014-10-30 18:44:00

+0

我更新了我的代码 – 2014-10-30 18:50:05

回答

-1

如果你想显示在浏览器动作徽章(出现在扩展程序工具栏图标顶部的小数字),您可以通过拨打来设置/更改该徽章10。