【问题标题】:my first extension - add bookmark with a click - HOW TO?我的第一个扩展 - 单击添加书签 - 如何?
【发布时间】:2011-08-05 13:31:15
【问题描述】:

我正在学习编写 javascript 和 Chrome 扩展程序。我想要一个显示按钮的扩展程序,当用户单击该按钮时,它会在书签中添加一个书签文件夹。
到目前为止一切顺利(按钮出现),但单击它不会添加任何内容。

我想我的 JavaScript 不正确。

代码如下:

清单:

{
  "name": "My First Extension",
  "version": "1.0",
  "background_page": "background.html",
  "permissions": [
    "tabs", "http://*/*", "bookmarks"
  ],
  "browser_action": {
      "default_icon": "icon.png",
      "name": "HELLO WORLD"
  }
}

背景.html:

<html>
<head>
<script>

  function updateIcon() {
    chrome.bookmarks.create({parentId: bookmarkBar.id,
                         title: 'Extension bookmarks'});
                  }

  chrome.browserAction.onClicked.addListener(updateIcon);
  updateIcon();

);
</script>
</head>
</html>    

我想是这部分:

function updateIcon() {    chrome.bookmarks.create({parentId: bookmarkBar.id,
                     title: 'Extension bookmarks'});
              }

那个代码是错误的。

请告诉我和任何学习 JavaScript 的好地方。我已经阅读了this web page

【问题讨论】:

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


【解决方案1】:

你有一个明显的语法错误。

  function updateIcon() {
    chrome.bookmarks.create({parentId: bookmarkBar.id,
                         title: 'Extension bookmarks'});
                  }

  chrome.browserAction.onClicked.addListener(updateIcon);
  updateIcon();

); // <-- what is this doing here?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多