Firefox插件获取标签正文内容 [英] Firefox add-on get the tab body content

查看:151
本文介绍了Firefox插件获取标签正文内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个关于Firefox附加组件的问题:

Hello everyone i have an question about firefox add-on:

例如,我可以从标签中获得正文内容。
$ b

How i can get the body content from a tab, for example.

var content = require("tabs").activeTab.documentContent.body.innerHTML;

非常感谢。

Thanks alot.

推荐答案

附加SDK不允许直接访问标签内容 - 这个想法是,附加组件和标签可能最终会生成在不同的进程中。你要做的是在标签中注入一个内容脚本来获得必要的数据,例如:
$ b

The Add-on SDK doesn't allow direct access to the tab contents - the idea is that the add-on and the tab might end up living in different processes eventually. What you do is injecting a content script into the tab to get you the necessary data, something like this:

var tab = require("tabs").activeTab;
tab.attach({
  contentScript: "self.postMessage(document.body.innerHTML);",
  onMessage: function(data)
  {
    console.log("Tab data received: " + data);
  }
});

这篇关于Firefox插件获取标签正文内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆