Head first JavaScript (iii)

Source: Internet
Author: User

SetTimeout, Unit is milliseconds

SetTimeout (time code, timer delay);

eg

SetTimeout ("Alert (' Wake up! ')", 100000);

The Document object represents the Web page code itself

Modify the User window (not the entire browser) size, can be used body.clientwidth, body.clientheight, so that can adapt to the size of different windows, if you want to dynamically according to the size of the current window to change the size, you can use onresize trigger.

function Resize () {    ...} ... <body onload = "resize ();" onresize = "resize ();" >

JavaScript clears all the variables when the browser is closed, so the entire script is rerun every time the page is reopened. If you need some variables that can be recorded and reused, you can use cookies to record the variables when you close the page.

Cookies

Name = Jackexpires 11/11/2014

The use of the cookie is to declare its expires end time, and the end time will be automatically deleted, if no declaration end time is treated as normal variable, when the browser is closed. Use between cookies; Examples of usage functions for cookies:

function Writecookie (name, value, days) {//By default , there is no expiration so the cookie is temporaryvar expires = "";//specifying a number of days makes the cookie Persis Tentif (days) {var date = new Date ();d ate.settime (Date.gettime () + (days * + *)); expires = "; Expires= "+ date.togmtstring ();} Set the cookie to the name, value, and expiration Datedocument.cookie = name + "=" + value + Expires + "; path=/";} function Readcookie (name) {//Find the specified cookie and return its valuevar searchname = name + "="; var cookies = docu Ment.cookie.split (';'); for (var i = 0; i < cookies.length; i++) {var c = cookies[i];while (C.charat (0) = = ")//Remove opening extra space c = c.substring (1, C . length); if (C.indexof (searchname) = = 0) return c.substring (Searchname.length, c.length);} return null; No results returned null}function Erasecookie (name) {//Erase the specified Cookiewritecookie (name, "",-1);}  

You can put these functions into a file in the. js suffix.

Navigator.cookieenabled can see if cookies are currently available

Head first JavaScript (iii)

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.