| 1313 | * Return true if object is probably a Node object. |
| 1314 | */ |
| 1315 | function is_node(object) |
| 1316 | { |
| 1317 | // I use duck-typing instead of instanceof, because |
| 1318 | // instanceof doesn't work if the node is from another window (like an |
| 1319 | // iframe's contentWindow): |
| 1320 | // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295 |
| 1321 | try { |
| 1322 | var has_node_properties = ("nodeType" in object && |
| 1323 | "nodeName" in object && |
| 1324 | "nodeValue" in object && |
| 1325 | "childNodes" in object); |
| 1326 | } catch (e) { |
| 1327 | // We're probably cross-origin, which means we aren't a node |
| 1328 | return false; |
| 1329 | } |
| 1330 | |
| 1331 | if (has_node_properties) { |
| 1332 | try { |
| 1333 | object.nodeType; |
| 1334 | } catch (e) { |
| 1335 | // The object is probably Node.prototype or another prototype |
| 1336 | // object that inherits from it, and not a Node instance. |
| 1337 | return false; |
| 1338 | } |
| 1339 | return true; |
| 1340 | } |
| 1341 | return false; |
| 1342 | } |
| 1343 | |
| 1344 | var replacements = { |
| 1345 | "0": "0", |