1

我希望为某个页面的所有传出链接激活我的页面操作。我该怎么做呢?我翻阅了文档无济于事。任何指针将不胜感激!

4

2 回答 2

1
  1. Google Chrome API 没有这样的 API,但是您想要的功能可以使用标准的 Google chrome Extensions API 来实现。
  2. 您需要实现内容脚本
  3. 您的内容脚本应该修改您要处理的页面的 DOM,并使用您的自定义 javascript 覆盖所有传出链接,这将做一些事情并打开点击的链接。

要修改链接 href,您可以执行以下操作:

function processLink(element, newHref) {
  var a = document.createElement("a");
  a.href        = newHref;
  a.textContent = element.textContent;
  a.title       = element.title;

  element.parentNode.replaceChild(a, element);
}

更新 1。

而不是 newHref 你可以生成类似的东西

a.href = "javascript:processOutgoingLinkClick('" + element.href + "')"

函数processOutgoingLinkClick应该包含点击的实际处理。

于 2010-03-20T16:49:36.997 回答
0

只是好奇,你为什么不使用可以监听 onUpdated onCreated的Chrome 扩展选项卡事件。当用户点击页面上的链接时,它会在 onUpdated 中触发一个事件。

因此,在您的 background.html 中,您可以执行以下操作:

chrome.tabs.onUpdated.addListener(function(tabId, info) {
  if (info.status === 'loading')
    console.log('Loading url ... ' + info.url)
});

onCreated 也是一样。然后在加载时,您可以决定如何处理您的 pageAction。

于 2010-03-20T19:48:41.847 回答