javascriptfirefoxxpathfirefox-addondocument.evaluate

Why isn't document.evaluate working?


I am using this in a Firefox extension and can't get it to work.

var allLinks = document.evaluate(
                        '//a[@href]', 
                        window.document, 
                        null, 
                        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, 
                        null);
window.alert(allLinks);

This alerts [object XPathResult]. However the following always returns 0. (And there are certainly links on the page).

window.alert(allLinks.snapshotLength);

Solution

  • This worked.

            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);