I am working on a Firefox extension in which I am trying to find if a given node intersects the selection range in a web page. For this, I am using the following code:
var rangeIntersectsNode = function(range, node) {
var nodeRange = node.ownerDocument.createRange();
try {
nodeRange.selectNode(node);
}
catch(e) {
nodeRange.selectNodeContents(node);
}
return range.compareBoundaryPoints(content.Range.END_TO_START, nodeRange) == -1 &&
range.compareBoundaryPoints(content.Range.START_TO_END, nodeRange) == 1;
}
When I use this code in Firefox version 9 or lower, I get an error in the console which says ownerDocument is null
Could anyone tell me what is wrong here and how I can set it right? Is there an equivalent api for older version of the browsers?
If this property is used on a node that is itself a document, the result is null.
See also:
Dom 2 spec