471,854 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

this == document

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

Not sure.
Sep 27 '09 #2
8,658 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
8,658 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
8,658 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
reply views Thread by NeoPa | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.