8.0 BOM Object

Source: Internet
Author: User

Master knowledge of the structure diagram
    
1 Window
2 Control window, frame, pop-up window
3 using the page information in the Location object
4 using Navigator objects to learn about browsers
the core object of the 1.1 BOM is window, which represents an instance of the browser. In the browser, the Window object has a dual role, which is both an interface for accessing the browser window through JavaScript, and the global object specified by the ECMAScript.
Global Scope
because window plays the role of the global object in ECMAScript, all variables and functions declared in the global scope become properties and methods of the Window object.
  
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........

  

8.0 BOM Object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.