469,320 Members | 2,153 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

this == document

how do you test if this is a reference to document?
this==document fails
Sep 27 '09 #1
6 1582
Markus
6,050 Expert 4TB
this === document ?

Not sure.
Sep 27 '09 #2
Dormilich
8,651 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. test == document
worked for me.

another test would be
Expand|Select|Wrap|Line Numbers
  1. obj.toString().indexOf("HTMLDocument") != -1
Sep 27 '09 #3
Oops! I have two documents, on inside an iframe in one. is there a way to see if it is a Document? (typeof this returns object, I need to be more specific)
Sep 27 '09 #4
Dormilich
8,651 Expert Mod 8TB
see above


________________
Sep 27 '09 #5
rnd me
427 Expert 256MB
duck type it:
Expand|Select|Wrap|Line Numbers
  1. if (this.body && this.getElementsByTagName ){
  2.   alert("this quacks like a document!");
  3. }
Sep 28 '09 #6
Dormilich
8,651 Expert Mod 8TB
@rnd me
there are cases possible, where this is also true for custom objects (so take care of what you duck tape)
Sep 28 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by chirs | last post: by
9 posts views Thread by alu | last post: by
2 posts views Thread by Gulliver | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.