| 967 | * Return true if object is probably a Node object. |
| 968 | */ |
| 969 | function is_node(object) |
| 970 | { |
| 971 | // I use duck-typing instead of instanceof, because |
| 972 | // instanceof doesn't work if the node is from another window (like an |
| 973 | // iframe's contentWindow): |
| 974 | // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295 |
| 975 | try { |
| 976 | var has_node_properties = ("nodeType" in object && |
| 977 | "nodeName" in object && |
| 978 | "nodeValue" in object && |
| 979 | "childNodes" in object); |
| 980 | } catch (e) { |
| 981 | // We're probably cross-origin, which means we aren't a node |
| 982 | return false; |
| 983 | } |
| 984 | |
| 985 | if (has_node_properties) { |
| 986 | try { |
| 987 | object.nodeType; |
| 988 | } catch (e) { |
| 989 | // The object is probably Node.prototype or another prototype |
| 990 | // object that inherits from it, and not a Node instance. |
| 991 | return false; |
| 992 | } |
| 993 | return true; |
| 994 | } |
| 995 | return false; |
| 996 | } |
| 997 | |
| 998 | var replacements = { |
| 999 | "0": "0", |