JavaScript Learning notes BOM

Source: Internet
Author: User

The core object of the BOM is window, which represents both the browser window and the visible area of the page, as well as the globe object in ECMAScript, all global variables and functions are its properties, and all the acoustic functions and other functions exist in its namespace.

One, window Windows related settings

1) Get the location of the browser window on the display

Depending on the browser, you can use Screenleft,screentop or Screenx,screeny, the cross-browser code is as follows:

// get the location of the browser var leftpos= (typeof Window.screenleft = ='number')? Window.screenLeft:window.screenX; var toppos= (typeof Window.screentop = ='number')? Window.screenTop:window.screenY;

2) Location of the Mobile browser window

Moveto,moveby. However, the method is generally disabled by the browser

3) Get the size of the browser window and the Large Ding browser window of the browser page viewport

Different browsers implement different methods, ultimately cannot determine the size of the browser window itself, but can get the size of the page viewport

//get the location of the browser viewportvarPagewidth=Document.innerwidth;varpageheight=Document.innerheight;if(typeofpagewidth!=" Number"){    if(document.compatmode=="Css1compat") {PageWidth=Document.documentElement.clientWidth; PageHeight=Document.documentElement.clientHeight; }Else{pagewidth=Document.body.clientWidth; PageHeight=Document.body.clientHeight; }}alert (PageWidth+","+pageheight);

4) Resizing the browser window

The Resizeto () and Resizeby () Two methods can be used, but this method is generally disabled.

Second, window-related global objects

1.location objects

1) Location is the property of the window and is the property of the document, which represents the access address of the current page.

2) Locaiton can access the relevant fields of the current URL address through the properties such as Host,href,pathname,protocol,search

3) Location can change the current access address. Use location.href= "New address" more

4) Location.reload () reload page

2.navigation objects

On behalf of the browser application, you can query the browser version, name and so on. Not many applications in practice.

3.history objects

This object holds the user's internet history, History.go (-N), History.go (n), if only forward/backward step, you can use back (), forward (), to imitate the browser's forward/backward operation.

Third, window-related global functions

Related tool functions provided by objects such as 1.math,date

2.window.open () Popup function, the method can navigate to a specific URL, can open a new browser window, accept four parameters, URL, window target, an attribute string ("_self,_blank,_parent, etc."), and whether the Boolean value of the currently loaded page is recorded in the browser history. Sometimes, pop-ups are limited by browser security restrictions.

3. Intermittent calls and timeout calls

SetTimeOut (): Accepts two parameters, function and after how long the function is called

SetInterval (): Accepts two parameters, the function and how long each interval is called once

4, System-related dialog box

Alert (), confirm (), prompt ()

The appearance of these dialog boxes is determined by the browser, not by the CSS, and the dialogs are both synchronous and modal, that is, when the dialogs are displayed, the code stops running until the dialog boxes are closed.

JavaScript Learning notes BOM

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.