0

我想在上下文菜单中添加一个书签。

这是我的书签:

javascript:(function(){var a=window.open(' http://localhost/test/mm.php?title= '+encodeURIComponent(document.title),'test','left='+((window .screenX||window.screenLeft)+50)+',top='+((window.screenY||window.screenTop)+50)+',height=300px,width=700px,resizable=1,alwaysRaised=1 ,location=1,links=0,scrollbars=0,toolbar=0');window.setTimeout(function(){a.focus()},300)})();

这是我的代码:

function getClickHandler() {
  return function(info, tab) {

  };
};

chrome.contextMenus.create({
  "title" : "Hello",
  "type" : "normal",
  "onclick" : getClickHandler()
});

但是现在,我不知道在哪里插入小书签。

@wong2:

这是我的新 getClickHandler 但它不起作用:

function getClickHandler() {
  return function(info, tab) {
      chrome.tabs.executeScript(tab.id, {
          code: "(function(){var a=window.open('http://localhost/test/mm.php?title='+encodeURIComponent(document.title),'test','left='+((window.screenX||window.screenLeft)+50)+',top='+((window.screenY||window.screenTop)+50)+',height=300px,width=700px,resizable=1,alwaysRaised=1,location=1,links=0,scrollbars=0,toolbar=0');window.setTimeout(function(){a.focus()},300)})();"
      });
  };
};

清单.json:

{
  "name" : "testtt",
  "version" : "1.0.1",
  "description" : "test button",
  "background" : { "scripts": ["background.js"] },
  "permissions" : [
    "contextMenus",
    "tabs",
    "http://*/*",
    "https://*/*"
   ],
  "minimum_chrome_version" : "6.0.0.0",
  "icons" : {
    "16" : "imageinfo-16.png",
    "48" : "imageinfo-48.png",
    "128" : "imageinfo-128.png"
  },
  "manifest_version": 2
}
4

1 回答 1

1

您可以尝试chrome.tabs.executeScript将代码插入页面:

function getClickHandler() {
  return function(info, tab) {
      chrome.tabs.executeScript(tab.id, {
          code: YOUR_CODE_IN_STRING_HERE
      });
  };
};
于 2012-05-23T16:35:49.543 回答