Connecting Tech Pros Worldwide Help | Site Map

this == document

Newbie
 
Join Date: Mar 2009
Posts: 24
#1: Sep 27 '09
how do you test if this is a reference to document?
this==document fails
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: Sep 27 '09

re: this == document


this === document ?

Not sure.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,641
#3: Sep 27 '09

re: this == document


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
Newbie
 
Join Date: Mar 2009
Posts: 24
#4: Sep 27 '09

re: this == document


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)
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,641
#5: Sep 27 '09

re: this == document


see above


________________
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#6: Sep 28 '09

re: this == document


duck type it:
Expand|Select|Wrap|Line Numbers
  1. if (this.body && this.getElementsByTagName ){
  2.   alert("this quacks like a document!");
  3. }
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,641
#7: Sep 28 '09

re: this == document


Quote:

Originally Posted by rnd me View Post

Expand|Select|Wrap|Line Numbers
  1. if (this.body && this.getElementsByTagName ){
  2.   alert("this quacks like a document!");
  3. }

there are cases possible, where this is also true for custom objects (so take care of what you duck tape)
Reply