1, BOM introduction
A BOM (Browser object model) that can be accessed and manipulated by the browser window. Using the BOM, developers can move the window, change the text in the status bar, and perform other actions that are not directly related to the content of the page.
Make JavaScript capable of "talking" to the browser.
2. Window Object
1 Window Object 2 window objects are supported by all browsers. 3 conceptually. An HTML document corresponds to a Window object. 4 Functionally speaking: Controls the browser window. 5 Use: The Window object does not need to create objects, directly to use.
Window object method:
1 alert () Displays a warning box with a message and a confirmation button. 2 confirm () displays a dialog box with a message along with a confirmation button and a Cancel button. 3 prompt () displays a dialog box to prompt the user for input. 4 5 open () opens a new browser window or looks for a named window. 6 Close () Closes the browser window. 7 SetInterval () invokes a function or evaluates an expression by the specified period (in milliseconds). 8 clearinterval () cancels the timeout set by SetInterval (). 9 SetTimeout () invokes a function or evaluates an expression after the specified number of milliseconds. Ten cleartimeout () cancels the timeout set by the SetTimeout () method. OneScrollTo () Scrolls the content to the specified coordinates.
Interactive methods:
1 Method explained:2----------Alert confirm Prompt----------------------------3Alert'AAA');4 5 6/* var result = confirm ("Are you sure you want to delete it?");7alert (result); */8 9//prompt Parameter 1: prompt information. Parameter 2: The default value for the input box. The return value is what the user entered.Ten Onevar result = prompt ("Please enter a number!","haha"); A//alert (result); - - the - Method explained: -//Open method opens and a new window and enters the specified URL. Parameter 1: URL. -//Call Mode 1 +Open"http://www.baidu.com"); -//parameter 1 Nothing is to open a new window. Parameter 2. Fill in the name of the new window (you can usually not fill in). Parameter 3: Parameters for the newly opened window. +Open"',"','width=200,resizable=no,height=100'); //opens a new window with a width of 200 and a height of 100 A//the Close method closes the current document window. atClose ();
View Code
setinterval clearinterval
1<input id="ID1"Type="text"onclick="begin ()">2<button onclick="End ()"> Stop </button>3 4<script>5 6 7 function ShowTime () {8var nowd2=new Date (). tolocalestring ();9var Temp=document.getelementbyid ("ID1");TenTemp.value=nowd2; One A } - - var clock; the - function begin () { - - if(clock==undefined) { + - showTime (); +Clock=setinterval (showtime,1000); A at } - - } - - function End () { - in clearinterval (clock); - } to +</script>
View Code
setTimeout cleartimeout
1 var ID = setTimeout (abc,2000); The corresponding function is called only once. 2 cleartimeout (ID); 3 function abc () {4 alert ('aaa'); 5 }
View Code3. History ObjectHistory Object Properties
The History object contains the URLs that the user has visited (in a browser window).
The history object is part of the Window object and can be accessed through the Window.history property.
1 Length Returns the number of URLs in the browser history list.
History Object Method
1 Back () loads the previous URL in the History list. 2forward () loads the next URL in the history list. 3 Go () loads a specific page in the History list.
1 <a href="rrr.html">click</a>2 <button onclick=" History.forward ()">>>></button>3 <button onclick=" history.back ()">back</button>4 <button onclick=" History.go () ">back</button>
Demo4. Location Object
The Location object contains information about the current URL.
The Location object is a part of the Window object that can be accessed through the Window.location property.
Location Object Methods
1 location.assign (URL) 2 location.reload () 3 location.replace (Newurl)//Note the difference from assign
JavaScript---BOM objects