Common properties and usage of JavaScript objects

Source: Internet
Author: User

What is the browser object model?

The browser object model (BOM Browser object models) is one of the components of JavaScript that provides an object that interacts independently of the content and browser windows, and uses the browser object model to interact with the HTML.

The objects in JavaScript are divided into:

A local object (native objects), a built-in object (built-in objects), and a host object (host objects). Local objects and host objects are generally used by many people.

What can I accomplish with the BOM (browser object model)?

(1) pop up a new browser window

(2) Move, close the browser window, and resize the window.

(3) Implement the forward and backward methods in the browser window.

A browser can be seen as a Window object, the following is a brief introduction of the three main properties of the introduction and use

1)Document: Provides the URL information for the current page (for example: http://cn.bing.com/) and can reload the current page to load a new page.

The syntax is as follows:

Document. Url

2)location: The common attribute of location is href, which can be reached by setting a different URL for this property.

The syntax is as follows:

1 <!--first define a function--2 functions Myclick () {3                 //  Positioning to Baidu home 4                 location.href = "http://www.baidu.com"; 5             }

3)history: can realize the forward and backward and refresh function

1 history.go (0)    // Refresh current page 2 history (). Go ( -1)    // back Page 3 history (). Go (1)    // forward one page

Here's the point, the timing function .

Time function is very useful to our future development Web engineer, the following describes the common methods and use of the timing function:

Common methods for timing functions:

1) setTimeout (): Used to call a function or evaluate an expression after a specified millisecond;

Grammar:

SetTimeout ("function name", MS);

2) setinterval (): Can call function or calculate expression according to the specified period;

Grammar:

SetInterval ("function name", number of seconds between periodic call functions);

Here are two simple examples of timers:

1.setTimeout ()

1 //Define a function2 functionRefresh ()3 {4Time.innerhtml=NewDate (). toLocaleString () + ' Week ' + ' Day 123456 '. CharAt (NewDate (). GetDay ());5SetTimeout ("Refresh ()", 1000);6 } 7 //call function, comma after the number of milliseconds (one minute =60 seconds =60000 milliseconds)8 varTimer=settimeout ("Refresh ()", 1000);

2.setinterval ()

1 // Define a function 2 function Refresh () 3 {4varnew  Date (); 5 document.form1.txt_time.value=newdateobj.tolocalestring (); // uses the current locale and has been converted to a string 6  7var

You can also use a timer to write a small program for entertaining,

Can change a picture every 1 seconds

12<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>3<title> Time Functions </title>4<script type= "Text/javascript" >5 //define variables, store picture names6 vari = 1;7         functionGo () {8             if(i<2) {9i++;Ten}Else { OneI= 1;//Picture loop print Complete re-assign initial value 1 A             } - //get Doc object with ID "IMA" and assign value (path) to src attribute again -             vardoc = document.getElementById ("Ima"); theDOC.SRC = ' images/iag/' + i + '. jpg '; -         } -SetInterval (Go, 1000); - +<body> - //src is a picture path, so the picture name is an array (because it is easy to step through it here) + A</body>

Common properties and usage of JavaScript objects

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.