// Set up a new document. var doc2 = document.implementation.createDocument('', '', null);
// Copy some nodes into doc2 var node1 = doc2.importNode(doc1.getElementById('1'), false); var node2 = doc2.importNode(doc1.getElementById('1'), false);
node1.appendChild(node2);
doc2.appendChild(node1);
// Create two ranges in doc1 to compare. var range1 = doc1.createRange();
range1.setStart(doc1.getElementById('1'), 0);
range1.setEnd(doc1.getElementById('2'), 0);
var range2 = doc1.createRange();
range2.setStart(doc1.getElementById('2'), 0);
range2.setEnd(doc1.getElementById('3'), 0);
// Create a range in doc2. var range3 = doc2.createRange();
range3.setStart(node1, 0);
range3.setEnd(node2, 0);
// Compare range1 and range2: Should return 1.
try { var result1 = range2.compareBoundaryPoints(Range.START_TO_START, range1);
}
catch (ex) {
}
ok(result1 === 1, "range1 and range2 are compared correctly.");
// Compare range1 and range3: Should throw DOMException WRONG_DOCUMENT_ERR.
try { var result2 = range3.compareBoundaryPoints(Range.START_TO_START, range1);
}
catch (ex) { var error = ex.name; var errorCode = ex.code;
}
ok(error == "WrongDocumentError", "The WrongDocumentError exception thrown when comparing ranges from " + "different documents ");
ok(errorCode == DOMException.WRONG_DOCUMENT_ERR, "The exception thrown when comparing ranges from different documents " + "has the code DOMException.WRONG_DOCUMENT_ERR");
ok(result2 === undefined, "range1 and range3 couldn't be compared as expected.");
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.