By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

What is the difference between window.parent and window?

P: n/a

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

--
Rob
Jan 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Jan 9 '06 #2

P: n/a
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.

--
Rob
Jan 9 '06 #3

P: n/a
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.

Jan 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.