与 HTML 页面交互 - Firefox:未定义内容
Interacting with HTML Page - Firefox: Content Not Defined
我这里有一个脚本,它正在提取网页中的链接。它正在返回错误“content is not defined
”。
// extract the links
var links = new Array();
for (i = 0; i < content.document.links.length; i++) {
var thisLink = content.document.links[i].toString();
//links.push(content.document.links[i].toString());
console.log(thisLink);
}
为了与 Firefox SDK 中的 HTML 文档交互,我需要导入库吗?
这取决于自执行匿名函数是什么时候运行。有可能是运行在定义window.document之前
在那种情况下,尝试添加一个侦听器
window.addEventListener('load', yourFunction, false);
// ..... or
window.addEventListener('DOMContentLoaded', yourFunction, false);
yourFunction () {
// some ocde
}
我这里有一个脚本,它正在提取网页中的链接。它正在返回错误“content is not defined
”。
// extract the links
var links = new Array();
for (i = 0; i < content.document.links.length; i++) {
var thisLink = content.document.links[i].toString();
//links.push(content.document.links[i].toString());
console.log(thisLink);
}
为了与 Firefox SDK 中的 HTML 文档交互,我需要导入库吗?
这取决于自执行匿名函数是什么时候运行。有可能是运行在定义window.document之前
在那种情况下,尝试添加一个侦听器
window.addEventListener('load', yourFunction, false);
// ..... or
window.addEventListener('DOMContentLoaded', yourFunction, false);
yourFunction () {
// some ocde
}