我在Firefox扩展中使用了它,但无法让它工作。
var allLinks = document.evaluate(
'//a[@href]',
window.document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
window.alert(allLinks);这会向[object XPathResult]发出警报。但是,下面的代码总是返回0。(当然,页面上也有链接)。
window.alert(allLinks.snapshotLength);发布于 2010-07-30 03:23:24
这起作用了。
var allLinks = top.document.getElementById("content").selectedBrowser.contentDocument.evaluate(
treeView.model[0].xpath,
top.document.getElementById("content").selectedBrowser.contentDocument,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);发布于 2010-07-29 03:02:23
如果它是特定于firefox的,并且我假设您只使用新版本..你不能使用querySelectorAll吗?
document.querySelectorAll('a[href]')还有--你是在DOM完全加载的时候做的吗?将它绑定到DOMContentLoaded或其他什么。
document.addEventListener('DOMContentLoaded', fn, false);xpath编辑:你的为我工作,。在控制台中已加载的现有页面上执行此操作。我很确定你是在任何东西存在之前查询的。
发布于 2010-07-29 03:06:49
你不想听到的答案--“对我有效”。
请参阅this example (我的警报3)。
你在哪种浏览器和什么版本上测试它?
https://stackoverflow.com/questions/3356387
复制相似问题