What is the difference between window.parent and window?

Discussion in 'Javascript' started by RobG, Jan 9, 2006.

  1. RobG

    RobG Guest

    In Firefox if an HTML page is not hosted inside a frame or iframe, the
    following return true:

    (window === window.self);
    (window === window.parent);


    But in IE they return false (using == returns true for both). Can
    someone explain why?

    Saying "It's DOM 0 so anything goes" is a cop-out. :)


    A test:

    function testSelf()
    {
    alert('window === window.self: ' + (window === window.self)
    + '\n'
    + 'window === window.parent: ' + (window === window.parent)
    );
    }

    window.onload = testSelf;


    And in a related incident... testThing() returns true in both browsers:

    function Thing(){
    this.mySelf = this;
    }

    function testThing()
    {
    var x = new Thing();
    return x.mySelf === x;
    }

    alert(testThing());
     
    RobG, Jan 9, 2006
    #1
    1. Advertisements

  2. RobG wrote:

    "In Firefox if an HTML page is not hosted inside a frame or iframe, the
    following return true:

          (window === window.self);
       (window === window.parent);

    But in IE they return false (using == returns true for both). Can
    someone explain why?
    Saying "It's DOM 0 so anything goes" is a cop-out. :)

    A test:
          function testSelf()
          {
              alert('window === window.self: ' + (window
    === window.self)
                      + '\n'
                      + 'window ===
    window.parent: ' + (window === window.parent)
    ;
          }
          window.onload = testSelf;"

    For what it's worth, this is the result with WebTV:

    window === window.self: true
    window === window.parent: true

    We are at the level of IE4, not completely though. As a matter of fact,
    barely IE4.

    With regards to the results you're getting at your end, and taking into
    consideration my very basic understanding of the difference between ==
    and ===, it's as if IE is saying it's sort of true but not exactly.
    Which doesn't make sense to me.

    Later, Art.
     
    X l e c t r i c, Jan 9, 2006
    #2
    1. Advertisements

  3. RobG

    RobG Guest

    X l e c t r i c wrote:
    [...]
    That's sad!

    Exactly. It says to me that they refer to the same object (==), but
    somehow that object is not identically equivalent (===) to itself.

    I thought maybe it was because the reference is different, but in then
    testThing() should also give false.
     
    RobG, Jan 9, 2006
    #3
  4. RobG wrote:

    "Exactly. It says to me that they refer to the same object (==), but
    somehow that object is not identically equivalent (===) to itself.

    I thought maybe it was because the reference is different, but in then
    testThing() should also give false."

    Even though parent and self are a reference to the window, I wondered if
    Explorer might be seeing window.parent and window.self as object object.

    But when I did a typeof check for window, window.parent, window.self,
    parent, and self, they all were object on both Explorer and Firefox.

    Yes, it was a waste of time checking the obvious, but now I no longer
    wonder. About that.

    Later, Art.
     
    X l e c t r i c, Jan 9, 2006
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.