this == document

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • byteit101
    New Member
    • Mar 2009
    • 25

    this == document

    how do you test if this is a reference to document?
    this==document fails
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    this === document ?

    Not sure.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Code:
      test == document
      worked for me.

      another test would be
      Code:
      obj.toString().indexOf("HTMLDocument") != -1

      Comment

      • byteit101
        New Member
        • Mar 2009
        • 25

        #4
        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)

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          see above


          _______________ _

          Comment

          • rnd me
            Recognized Expert Contributor
            • Jun 2007
            • 427

            #6
            duck type it:
            Code:
            if (this.body && this.getElementsByTagName ){
              alert("this quacks like a document!");
            }

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by rnd me
              Code:
              if (this.body && this.getElementsByTagName ){
                alert("this quacks like a document!");
              }
              there are cases possible, where this is also true for custom objects (so take care of what you duck tape)

              Comment

              Working...