We know that the browser object model (BOM) is one of the components of javascript, which provides objects that interact with the browser window independently of the content. Its hierarchical structure is as follows:
The window object is the core of the entire BOM, which includes document (document object), location (address object) and history (composition of historical objects).
Syntax for calling object properties:
1. Object. Attribute name = "Attribute value";
2. Object ["Attribute Name String"] = "Attribute Value";
Syntax for calling object methods:
1. The method name of the object ();
2. Object ["Method Name String"]();
Common methods of window objects
Common methods of window objects
| name | illustrate |
| prompt() | Displays a dialog box that prompts the user to enter |
| alert() | Shows a warning dialog with a big prompt message and an OK button |
| confirm() | Display a dialog box with a prompt message, "OK" and "Cancel" buttons |
| close() | Close the browser window |
| open() | Open a new browser window to load the document specified by the given URL |
| setTimeout() | Call a function or calculate an expression after specifying a number of milliseconds |
| setInterval() | Call a function or calculate an expression according to the specified period (recorded in milliseconds) |
Feature properties of window
| name | illustrate |
| height, width | Height and width (recorded in pixels) |
| left, top | The x and y coordinates of the window are recorded in pixels |
| toolbar | Whether to display the browser's toolbar |
| scrollbars | Whether to display scrollbars |
| location | Whether to display the address bar |
| status | Whether to add a status bar |
| menubar | Whether to display the menu bar |
| Resizable | Is the window adjustable in size |
| titlebar | Whether to display the title bar |
| fullscreen | Whether to use full screen mode to display the browser |
Common events for window objects
| name | illustrate |
| onload | A page or image is loaded |
| onmouseover | Move the mouse pointer over an element |
| onclick | Click an object with the mouse |
| onkeydown | A keyboard key is pressed |
| onchange | The content of the domain has been changed |
Custom object declaration
The first way to declare:
<script type="text/javascript"> function paly() { var p = new Object();//Create an Object object to open up memory space//Define attributes for object p p.age = 1; p.name = "javascript"; //Define method for object p p.sayHi = function () { document.write("Hello everyone! I am" + p.name + "I am this year" + p.age + "year-old"); } //Return object p return p; } //Create instances of custom object var js = paly(); //Calling method of object js.sayHi(); //Calling the object's attribute document.write(js.name); </script>Effect screenshot:
The second method:
<script type="text/javascript"> function paly() { //Define the attributes for the object this.age = 1; this.name = "javascript"; //Define the method for the object this.sayHi = function () { document.write("Hello everyone! I am" + this.name + "I'm this year" + this.age + "year-old"); } } //Create an instance of a custom object var js = new paly(); //Calling the method of the object js.sayHi(); //Calling the attributes of the object document.write(js.name); </script>Effect screenshot:
Traversal of object properties
<script type="text/javascript"> function paly() { //Define the attributes for the object this.age = 1; this.name = "javascript"; //Define the method for the object this.sayHi = function () { document.write("Hello everyone! I am" + this.name + "I am this year" + this.age + "year-old"); } } //Create an instance of a custom object var js = new paly(); //Tranquility the attributes of the object for (var par in js) { document.write("js."+par+"="+js[par]); } </script>Effect screenshot:
Fast structure
<script type="text/javascript"> function paly() { //Define attributes for the object this.age = 1; this.name = "javascript"; //Define method for the object this.sayHi = function () { document.write("Hello everyone! I am" + this.name + "I am this year" + this.age + "year-old"); } } //Create an instance of a custom object var js = new paly(); //The methods or attributes in the structure block are defaulted to the attributes or methods of the (js) object in brackets if the object is not specified. { sayHi(); document.write("<br/>"+age); } </script>Effect screenshot:
The above summary of related operations of javascript objects is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.