Front-end scrambled JavaScript learning Note five

Source: Internet
Author: User

1 Window object:

All Browsers support window objects, which represent browser windows. All JavaScript global objects, global functions, and variables automatically become members of the Window object. A global variable is a property of a Window object, and a global function is a method of a Window object.

Three ways to determine the size of the browser's viewable window (except for toolbars and scroll bars):

(1) Window.innerheight get the visual height of the browser, Window.innerwidth get the viewable width of the browser. (Internet Explorer, Chrome, Firefox, Opera, and Safari)

(2) Document.documentelement.clientheight,document.documentelement.clientwidth (Internet Explorer 8, 7, 6, 5)

(3) Document.body.clientheight,document.body.clientwidth.

Methods for some window objects:

window.open (): Open window

Window.close (): Close window

Window.resize (): Adjusts the size of the current window

Window.moveto (): Move the current window

2 Window.screen:

Window.screen object does not need to write the prefix window when used, its properties such as: screen.availwidth (usable width), screen.availheight (usable height)

3 window.location:

The Window.location object can omit the prefix window when it is used, and its properties are as follows:

Location.href: Returns the URL of the current page

Location.hostname: Returns the domain name of the web host

Location.pathname: Returns the path and path name of the current page

Location.port: Returns the port number of the current web host

Location.protocol: Returns the Web protocol used

The Location.assign () method can be used to load a new document.

4 Window.history:

The Window.history object can omit the prefix window when it is used, because it involves user privacy, and JavaScript makes some restrictions on its use.

History.back () is the same as clicking the Back button on the browser, which is the previous URL to load the history list

History.forward () is the same as clicking the Forward button on the browser, which is the next URL to load the history list

5 Window.navigator

The Window.navigator object can omit the prefix window when it is used

The information from the Navigator object is misleading and should not be used to detect browser versions because:

    • Navigator data can be changed by browser user
    • The browser cannot report a new operating system that is later than the browser published
Browser detection

Because navigator can mislead browser detection, using object detection can be used to sniff out different browsers.

Because different browsers support different objects, you can use objects to detect the browser. For example, opera can be identified by only opera's support for the attribute "Window.opera".

Example: if (Window.opera) {... some action ...}

6 JavaScript in mind:

With JavaScript, it is possible to implement a function when it is no longer being invoked, but only after a definite period of time.

The two key functions for implementing the notation are:

SetTimeOut (): Sets how long the code will be executed in the future, and the SetTimeOut () method returns a value. For example, a value is stored in a variable named T. If you want to cancel the setTimeout (), you can use the variable name to specify it. The first argument to SetTimeout () is a string containing a JavaScript statement. This statement may be such as "alert (' 5 seconds! ')" or a call to a function, such as alertmsg () ". The second parameter indicates how many milliseconds from the current start to execute the first parameter.

Cleartimeout (): Cancels settimeout.

7 JavaScript Cookies:

Cookies are variables stored on the visitor's computer, which are sent whenever a browser requests a page through a browser, and JavaScript can be used to create and retrieve the value of a cookie.

Name Cookie When a visitor first visits a page, he or she may fill out his or her name. The name is stored in a cookie. When visitors visit the site again, they receive a welcome word like "Welcome John doe!". And the name is retrieved from the cookie. Password cookie When a visitor visits the page for the first time, he or she may fill in his/her password. The password can also be stored in a cookie. When they visit the site again, the password is retrieved from the cookie. Date cookies The current date can be stored in a cookie when the visitor first visits your website. When they visit the site again, they receive a message like this: "Your last Visit is on Tuesday August 11, 2005!". The date is also retrieved from the cookie.

Front-end scrambled JavaScript learning Note five

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.