BOM Browser Object Model
A BOM (browser object Model) that provides objects that interact with a browser window.
first, window Object
The Window object represents the entire browser window.
Window objects are supported by all Browsers. It represents a browser window.
All JavaScript global objects, functions, and variables automatically become members of the window Object.
A global variable is a property of a window Object.
A global function is a method of a window Object.
Even the document of the HTML DOM is one of the properties of the window Object.
(1). System message box alert ()
Example: Alert (' Hello ');
(2). Confirmation dialog box confirm ()
The method returns a Boolean value, and if clicked OK returns true, Click Cancel to return false;
Example: if (confirm ("ok to Delete?")) {
Delete
}
(3). Input dialog box prompt ()
If you click OK to return the value in the text box as a function value, click Cancel to return null
example: var name = prompt ("please Enter your Name?") ","");
If (name! = Null) {
Alert (' Welcome ' + name);
}
(4). Open a new window window.open ()
Cases:
window.open ("http://www.baidu.com", "_blank", "width=500, height=500");
Note: to remove the browser blocking Feature.
(5). Timer
A, Window.setinterval (); Setting the loop Timer
The SetInterval () method invokes a function or evaluates an expression according to the specified period (in milliseconds).
SetInterval (code,millisec,lang)
Parameters |
Describe |
Code |
Necessary. The function to invoke or the code string to Execute. |
Millisec |
Have to. The time interval, in milliseconds, between periodically executing or calling Code. Note: 1000ms=1s |
Lang |
Optional. JScript | VBScript | Javascript |
B,window. Clearinterval (); Clear the Loop timer
C, Window.settimeout (); Set up a single time timer
D, window.cleartimeout () Clear a single time timer
Here's an example: setting a real-time clock
JS Code:
<script type= "text/javascript" >functiontime () {varMydate=NewDate (); varYear=Mydate.getfullyear (); Get the full yearvarMonth=Mydate.getmonth (); Get the current month (0-11, 0 for January)varday=mydate.getdate (); Get Current day (1-31)varhours=mydate.gethours (); Gets the current number of hours (0-23)varmin=mydate.getminutes (); Gets the current number of minutes (0-59)varSecond=Mydate.getseconds (); Gets the current number of seconds (0-59)
var week=mydate.getday (); Get current week (0-6,0 is Sunday)
var weekday=[' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '
document.getElementById ("clock"). innerhtml= "now is:" +year+ "year" +month+ "month" +day+ "day" +hours+ ":" +min+ ":" + Second+
window.setinterval ("time ()"), +//set timer with 1s timing.
</script>
HTML code:
<onload= "time ()"> <ID= "clock"></div></body>
The output is:
It should have been animated, but here is the Picture. You can copy the code to see the effect yourself.
Ii. history Object
The history object is a child object of the Window object , corresponding to the Browser's
Historical RECORDS.
History.back (); Same as clicking Back button in browser
History.forward ();//the Same as clicking the button in the browser
third, location Object
The location object is also a child of the Window object , which allows you to get or set the current address of the Browser.
1. Jump to another page
Window.location.href = "http://www.163.com";
Location.href = "http://www.163.com";
2. Reload page (refresh)
Location.reload ();
Iv. Navigator Object
The Navigator object contains information about the Web browser, which is also a property of the window and can be used
Window.navigator reference it, or you can use the Navigator reference
Example: get the browser internal code, name, operating system and other information
var info = navigator.useragent;
Alert (info);
JavaScript basic Syntax (v)