The Window object in JavaScript

Source: Internet
Author: User
Tags setinterval


JavaScript includes three parts: ECMAScript, BOM, and Dom. The Window object belongs to the BOM.

Window object, is the JS top-level object, representing the entire browser window, not only the JS content, the entire HTML page (including all elements and CSS content) is also under the Window object management.


Example

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "HTTP// Www.w3.org/TR/html4/loose.dtd ">

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/86/A0/wKioL1fFtm_zsp7TAAHxXy55Fz0755.gif "title=" window _var_func.gif "alt=" Wkiol1fftm_zsp7taahxxy55fz0755.gif "/>


The browser creates a Window object for each tabbed page, and the browser window sometimes opens multiple pages, which correspond to multiple window objects, each of which has almost no effect on each Window object.


1. Global Objects (properties)


1.1. Location Address Bar Object

HREF attribute

Reload () method

Sample code

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "HTTP// Www.w3.org/TR/html4/loose.dtd ">

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/86/A0/wKiom1fFt3bwqil8AAEFiBoQkVw330.gif "title=" window _location_href.gif "alt=" Wkiom1fft3bwqil8aaefiboqkvw330.gif "/>



1.2, Screenx and Screeny


Screenx the distance from the left border of the display browser

ScreenY


1.3. Document

Document page Documents object, representing an HTML page


1.4. Event

ClientX

ClientY

Window.event is a very important property that is used to obtain information when an event occurs.

Events are not confined to the event of a Window object, and events for all elements can be obtained through the event property. (not compatible with Firefox)


Example code one (Firefox is not compatible, IE can)

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "HTTP// Www.w3.org/TR/html4/loose.dtd ">

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/86/A0/wKiom1fFuObD0UiEAAGOs7jls-0662.gif "title=" window _event_clientxy.gif "alt=" Wkiom1ffuobd0uieaagos7jls-0662.gif "/>



Example code two (Firefox compatible)

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "HTTP// Www.w3.org/TR/html4/loose.dtd ">

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/86/A0/wKioL1fFubmi5iEaAAH6H1T4KZ8167.gif "title=" window _event_clientxy_func.gif "alt=" Wkiol1ffubmi5ieaaah6h1t4kz8167.gif "/>



2, Window's global function

Alert ()

Confirm ()

var result = Window.confirm ("Are you sure you want to delete this data?") "); alert (result);//true, False

Prompt ()

var result = window.prompt ("Please enter your name", ""); alert (result);//If you click Cancel, a null value is returned

Close ()

var result = Window.confirm ("Are you sure you want to close the current window?") "), if (result) {window.close ();}

Open ()

SetInterval (), Clearinterval ()

SetInterval ("a"), 1000);//execute only once setinterval (function () {alert ("a");},1000);//execute once every second


Sample code

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "HTTP// Www.w3.org/TR/html4/loose.dtd ">

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/86/A0/wKioL1fFu6HR4bekAAKDqBhg5nE917.gif "title=" window _setinterval.gif "alt=" Wkiol1ffu6hr4bekaakdqbhg5ne917.gif "/>

SetTimeout (), cleartimeout ()








The Window object in JavaScript

Related Article

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.