JavaScript-- gallop script execution's Web page (9)

XIV browser object model ( Bom )

Bom these common objects:

Window : encapsulates the entire browser window object

Navigation : encapsulates information about the browser

Screen : encapsulates the operating system screen information

History : encapsulates the browser access history information

LOCATION : encapsulates the browser address bar information

 

1.location objects

location object is the most useful BOM one of the objects, provide information about the document is loaded with the current window, it also provides a number of navigation. location is a magical objects, both window object is the document object.

console.log(window.location == document.location); //true

 

location object has these attributes:

host: Returns the server name and port number

hostname: Returns the server name with port numbers

href: Back to full currently loaded page URL

pathname: Returns the URL directories and file names

port: Returns the URL port number specified

protocol: Returns the protocol used by the page

search: Returns the URL query string. The string begins with a question mark

 

location object has these methods:

assign (): argument is a url , open a new url , and generate a record in your browsing history

replace (): argument is a url, the result will cause the browser address location change, but will not generate a new record in history

reload (): reload the current page displayed parameter can be boolean type, the default is false , it expressed in the most effective way to reload, may be loaded directly from the cache. If the argument is to true , it will be forced to re-loaded from the server

 

To window.location; location.href to a URL value, this value will be called to assign () method. The following three lines effect the same:

window.location="http://www.baidu.com";

location.href="http://www.baidu.com";

location.assign("http://www.baidu.com");

 

2.history objects

This object holds the history of Internet users. For security reasons, the developer does not know the user visited URL , but by a list of pages accessed by the user through, the same can not know the actual URL achieved in the case of the back and forth, to note that there is no applied History open standard object, but all browsers support the object. It has these properties and methods:

length: Returns the number of URL in the history list (IE and Opera from 0 start, while Firefox , Chrome and Safari from 1 start )

back (): Load history a former list of URL

forward (): Load history under a list of URL

go (): load history of a particular page in the list , a negative number indicates a jump backward, positive number indicates a jump forward

 

3. timeout call and intermittent call

JavaScript is a single-threaded language, but it may be scheduled at a particular time through code execution timeout value and the time interval :

setTimeout (): time-out call, the method comprises two parameters , namely, the code to be executed and the time in milliseconds , the result returns a value ID , the time-out call ID is a unique identifier code execution plan , by clearTimeout (ID) to cancel the timeout call

setInterval (): indicates the specified time interval is repeatedly executed code until the intermittent call was canceled or page is unloaded , the method comprises two parameters , namely, the code to be executed and the time in milliseconds, call the method also returns an intermittent call ID , can clearInterval (ID) to cancel the intermittent call

Calling a timeout can also simulate a batch call, for example:

var n = 0;

where max = 10;

function incrementNum(){

a ++;

if(num < max){

alert(num);

setTimeout(incrementNum,500);

}else{

alert("Done"+num);

}

}

setTimeout(incrementNum,500);

 

4. A system dialog

Alert () , Confirm () , prompt () method can be called system dialog box message is displayed to the user. These dialog boxes are displayed when the code stops executing, switch off after these dialog boxes will resume execution of code.

Alert () : prompt box, the method receiving a string parameter and displayed to the user. The dialog box that contains the specified text and an OK button, mainly used to display a warning message, no return value

Confirm () : confirmation dialog, which receives a string parameter and displayed to the user. The specified text and a display comprising the OK button, and Cancel buttons, the method returns a Boolean value, to true clicked the OK , to false indicating that clicking cancel or close button

prompt () : Session box that prompts the user to enter some text. The method receives two parameters, namely the text to be displayed to prompt the user and the default value of the text entry field, and the display contains a specified text OK button, and Cancel buttons, the method returns to the input value of the user

 

Guess you like

Origin www.cnblogs.com/wodeqiyuan/p/11496501.html