Chrome扩展程序:无法创建标签

时间:2013-08-17 15:24:12

标签: google-chrome-extension

只是尝试创建一个简单的标签,我无法让它工作。我有什么想法吗?

的manifest.json

{
  "manifest_version": 2,
  "browser_action": {
      "default_icon": {
          "19": "logo_19.png"
      },
      "default_title": "Test Suite",
      "default_popup": "main.html"
   },  
   "description": "Test Suite Description",
   "icons": {
      "128": "icon_128.png",
      "16": "icon_16.png"
   },   
   "name": "Test Suite",
   "permissions": ["http://www.google.com/"],
   "version": "1.0"
}

main.html中

<html>
<head>
<script type="text/javascript" src="popup.js">
</script>
</head>
<body>
    <div id="menu-items-ui">    
    <div id="registration">
     Google Search
      </div>
     </div>
</body>
</html>

popup.js

<script type="text/javascript"> 
document.addEventListener('DOMContentLoaded', function() {
    var registration = document.getElementById('registration');
    registration.addEventListener('click', function() {
        chrome.tabs.create({ url: 'http://www.google.com' });
    }); 
});
</script>

它不会去谷歌网站。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

你的javascript文件中有html,删除它

popup.js

document.addEventListener('DOMContentLoaded', function() {
    var registration = document.getElementById('registration');
    registration.addEventListener('click', function() {
        chrome.tabs.create({ url: 'http://www.google.com' });
    }); 
});