JavaScript window operations

Source: Internet
Author: User

Note: This document is for W3school learning and collation

BOM Browser object Model (Browser )

1. Get the size of the window

var W=window.innerwidth | | Document.documentElement.clientWidth | | Document.body.clientwidth;var H=window.innerheight | | Document.documentElement.clientHeight | | Document.body.clientHeight;

2. window.open ()-Opens a new window,

3. Window.close ()-Close the current window,

4. Window.moveto ()-Moves the current window,

5. Window.resizeto ()-Adjusts the size of the current window

6. The Window.screen object contains information about the user's screen.

<script>document.write ("Usable width:" + screen.availwidth);d ocument.write ("Available height:" + screen.availheight); </script >

7. The Window.location object can be written without using the window prefix.

Location.hostname returns the domain name of the web host
Location.pathname returns the path and file name of the current page
Location.port returns the port of the web host (80 or 443)
Location.protocol returns the Web protocol used (HTTP///https://)
The Location.href property returns the URL of the current page
Location.assign (URL) method to load a new document

8. The Window.history object can be written without using the window prefix.

History.back ()-Same as clicking Back button in browser
History.forward ()-Same as clicking the button in the browser forward

9. The Window.navigator object contains information about the visitor's browser. The Window.navigator object can be written without using the window prefix. Navigator data can be changed by the browser user. Because only opera supports the attribute "Window.opera", you can identify opera accordingly.

<script>txt = "<p>browser codename:" + Navigator.appcodename + "</p>"; txt+= "<p>browser Name:" + Navigator.appname + "</p>"; txt+= "<p>browser Version:" + navigator.appversion + "</p>" txt+= "<P&G T Cookies Enabled: "+ navigator.cookieenabled +" </p> "txt+=" <p>platform: "+ navigator.platform +" </p> "; txt+=" <p>user-agent header: "+ navigator.useragent +" </p> "txt+=" <p>user-agent language: "+ Navig Ator.systemlanguage + "</p>";d Ocument.getelementbyid ("example") .innerhtml=txt;</script>

10. You can create three message boxes in JavaScript: A warning box, a confirmation box, and a prompt box.

Warning Box: alert ("text")
Confirmation Box: Confirm ("text"); If the user clicks Confirm, then the return value is true. If the user clicks Cancel, the return value is false.
Prompt box: prompt ("text", "Default value"); If the user clicks Confirm, then the return value is the value entered. If the user clicks Cancel, the return value is null.

One. JS Implementation timing

Start, turn off features

Real Time timekeeping

A cookie is a variable stored on a visitor's computer. This cookie is sent whenever a page is requested by the same computer through a browser. You can use JavaScript to create and retrieve the value of a cookie.

  

  

  

  

  

JavaScript window operations

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.