The browser object model for the JavaScript starter Chapter

Source: Internet
Author: User

Preface:

The real JavaScript is made up of three parts, ECMAScript, DOM, and BOM, as shown in. This article will mainly cover the browser object model. The BOM (Browser object mode) is a model of browser objects that describes the hierarchical relationship between objects and objects, and the browser object model provides a content-independent object structure that can interact with the browser window. A BOM consists of multiple objects, which represent the window object of the browser windows as the top-level object of the BOM, and the other objects are child objects of that object.





First, Window object


A BOM can be used to access and manipulate the browser window's browser, which the developer can use to control the browser from displaying parts of the page. It provides a lot of objects to help us access the browser. The core object is window, which represents an instance of the browser. The Window object is at the top level of the JavaScript structure, and there is a default window object for each open windows.


Properties of the Window object:


Method of the Window object:




There are the alert (), confirm (), prompt () methods that we often use in the method to invoke the System dialog box to display the information to the user. Because the Window object is a global object, you do not need to add a window to its properties and methods. Instead, you can call them directly, as we have seen in instances where we have directly invoked the alert () method.



Application Examples:

      Determine and Cancel                  if (Confirm (' Please confirm or Cancel ')} {             alert ("OK to be sure?") ")         }         else {             alert (" OK to cancel? ") ")         }

The immediate descendants of the window object do not require a window prefix, but when working with objects other than the immediate descendants of the Window object, you need to precede them with the name of the Window object. For example, the Document object is a direct descendant of the Window object, so the window prefix is not required, but the document object's descendants require the document prefix.

Examples are as follows:

         Alert (' something ');  Note No window         document.forms[0]    //note the document



Ii. Location Object


The Location object allows us to access the currently loaded URI, including any information about the query string, the protocols used, and other related components.

Location Properties:

Location method:



Application Examples:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><body>    <script lang= "Javasctript" type= "Text/javascript" >        var BODY = document.getElementsByTagName ("body") [0];        for (Var prop in navigator) {    &NB Sp       var elem = document.createelement ("P");            var text = document. createTextNode (prop + ":" + Navigator[prop]);            Elem.appendchild (text);  &nbs P         Body.appendchild (elem);       }        if (location.s earch) {            var querystring = localtion.search;          &N Bsp var splits = querystring.splits (' & ');            for (var i = 0; i < splits.length; I + +) {                var splitpair = SplitS[i].split (' = ');                var elem = document.createelement ("P");  &nbs P             var text = document.createTextNode (splitpair[0] + ":" + splitpair[1]);  &NB Sp             Elem.appendchild (text);                B Ody.appendchild (elem);           }       }    &LT;/SCRIPT&GT ;</body></span>



Third, the history of the object


The history object provides a way to move forward and backward through the visitors ' browsing histories. Specifically, you can use back (), forward (), go (). This may be self-evident, but also to illustrate: back () and forward () move backward and forward one page, the Go () method moves to the index value specified by the parameter.



Application Examples:

    function back ()         {             history.back ();         }    function forward ()         {             history.forward ();         }                 <p><a href= "#" onclick= "return Back ();" >click to go back</a></p>         <p><a href= "#" onclick= "return Forward ();" >click to go forward</a></p>



Iv. Summary


Some important objects in the browser object model require further practice to master some of the commonly used properties and methods.


The browser object model for the JavaScript starter Chapter

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.