1 var age = 29;2 function Sayage () {3 alert (this.age); 4}5 6 alert (window.age);//297 sayage ();//298 window.sayage (); 29
Here's a point to remember:
There are some differences between the defined global variables and the variables defined directly on the window:
<1> variables that are defined directly on window can be deleted using delete
<2> var declares that global variables cannot be used; this is the [[configurable]] in the attribute description object described in the previous section, and the value declared by Var defaults to False
1Window.age = 20;2 3 varcolor = "Red";4 5Console.log (DeleteColor//false <IE9 will error6Console.log (color);//Red7 8Console.log (DeleteAge);//true <IE9 will error9Console.log (Window.age);//undefined
When a global variable is referenced, the window calls an undefined property without an error, and the direct call causes an error
Window.age =; Delete age; Console.log (Window.age); Undefind Console.log (age); "Referenceerror:age is not Definede
2.1 The relationship between windows and frames
1 each frame has its own window object and is saved in the Frames collection.
2 in the Frames collection, the corresponding Window object is accessed by index starting from 0 (left to right, top to bottom) or frame name.
Main.html
<Scripttype= "Text/javascript"> functionload () {Console.log (window.frames[0]); Console.log (window.frames["Topframe"]); Console.log (top.frames[0]); Console.log (top.frames["Topframe"]); Console.log (frames[0]); Console.log (frames["Topframe"]); }</Script><Framesetrows= "160,*"onload= "load ()"> <Framesrc= "top.html"name= "Topframe"> <Framesetcols= "50%,50%"> <Framesrc= "left.html"name= "Leftframe"> <Framesrc= "right.html"name= "Rightframe"> </Frameset>
</frameset>
Top.html
<!DOCTYPE><HTML> <HEAD> </HEAD> <BODY> <ul> <Li>Window.frames[0]</Li> <Li>window.frames["Topframe"]</Li> <Li>Top.frames[0]</Li> <Li>top.frames["Topframe"]</Li> <Li>Frames[0]</Li> <Li>frames["Topframe"]</Li> </ul> </BODY></HTML>
Left.html
<!DOCTYPE><HTML> <HEAD> </HEAD> <BODY> <ul> <Li>WINDOW.FRAMES[1]</Li> <Li>window.frames["Leftframe"]</Li> <Li>TOP.FRAMES[1]</Li> <Li>top.frames["Leftframe"]</Li> <Li>FRAMES[1]</Li> <Li>frames["Leftframe"]</Li> </ul> </BODY></HTML>
Right.html
<!DOCTYPE><HTML> <HEAD> </HEAD> <BODY> <ul> <Li>WINDOW.FRAMES[2]</Li> <Li>window.frames["Rightframe"]</Li> <Li>TOP.FRAMES[2]</Li> <Li>top.frames["Rightframe"]</Li> <Li>FRAMES[2]</Li> <Li>frames["Rightframe"]</Li> </ul> </BODY></HTML>
See how each frame is accessed through the outermost layer,
Top represents the outermost frame, which is the browser window. Use it to ensure that the contents of each frame are accessed in the correct order.
The window object points to an instance of that frame. Does not mean the outermost layer;
Another window object relative to top, parent, Gu Mingsi the parent window to the current window, and in some cases top may be equal to the parent (outermost). However, in the absence of a frame, top must be equal to the parent;
The self object associated with the form, always pointing to the Window object, and self can be used interchangeably with window just to correspond to top, parent, no special meaning
All of these objects are properties of the Window object and can be accessed through the Window object to Window.parent, Window.top
2.1.1 The location of the window
|
Screenleft |
Screentop |
ScreenX |
ScreenY |
| Ie |
Y |
Y |
|
|
| Safari |
Y |
Y |
Y |
Y |
| Opera |
Y |
Y |
|
|
| Chrome |
Y |
Y |
Y |
Y |
| Firefox |
|
|
Y |
Y |
Get form location information
var toppos = (typeof window.screentop== "number")? Window.screenTop:window.screenY;
var leftpos = (typeof window.screenleft== "number")? Window.screenLeft:window.screenX;
In these several properties, there are some differences between the different browsers:
In IE, Opera, Chrome, Firefox, Safari, Screenleft and Screentop are saved from the left and top of the screen to the page distance represented by the Window object.
Go on........