What is the difference between window.parent and window?

R

RobG

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());
 
X

X l e c t r i c

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.
 
R

RobG

X l e c t r i c wrote:
[...]
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.

That's sad!

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.

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.
 
X

X l e c t r i c

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,249
Members
46,847
Latest member
FlorrieSha

Latest Threads

Top