Connecting Tech Pros Worldwide Forums | Help | Site Map

What is the difference between window.parent and window?

RobG
Guest
 
Posts: n/a
#1: Jan 9 '06

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

X l e c t r i c
Guest
 
Posts: n/a
#2: Jan 9 '06

re: What is the difference between window.parent and window?


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.

RobG
Guest
 
Posts: n/a
#3: Jan 9 '06

re: What is the difference between window.parent and window?


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

That's sad!

[color=blue]
> 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.[/color]

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
X l e c t r i c
Guest
 
Posts: n/a
#4: Jan 9 '06

re: What is the difference between window.parent and window?


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.

Closed Thread