LikeYou
LikeYou

Reputation: 500

JavaScript - multiple global objects in multiple HTML frames?

Do we have multiple (different) global objects in a multi-frame frameset HTML?

It's common to use:

 if(window.top != window.self) {
   alert("We're in a frame");
 }

where window is a property of the [[global]] object like self is, and both are references to [[global]] object itself. But, if window.top refers to the topmost window frame object and therefore to the [[global]] object, how many [[global]] objects do we have? Or maybe the window DOM part is changed only?

Upvotes: 6

Views: 1556

Answers (1)

salezica
salezica

Reputation: 76929

Each document (therefore each frame) has its own window object.

The window object is not a unique singleton. It's just an instance of Window. One is created for each document, and can be accessed through document.defaultView.

If and only if two pieces of your application share a document, they share a window.

There is no [[global]] object: global scope is just a way of conveniently accessing the current window.

Upvotes: 2

Related Questions