Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 280
LikeYou Avatar asked Aug 12 '14 19:08

LikeYou


1 Answers

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.

like image 116
slezica Avatar answered Oct 29 '22 13:10

slezica