Browser object Model BOM (Browser object models)
Because modern browsers have (almost) implemented the same methods and properties of JavaScript interactivity, they are often considered to be the methods and properties of the BOM
Window Object
Window objects represent open windows in the browser.
If the document contains a frame (frame or iframe label), the browser creates a Window object for the HTML document and creates an additional window object for each frame.
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.
Window size
The viewport of the browser, excluding toolbars and scroll bars.
For Internet Explorer, Chrome, Firefox, Opera, and Safari:
For Internet Explorer 8, 7, 6, 5:
Or
Instance
var w=window.innerWidth|| document.documentElement.clientWidth|| document.body.clientWidth;var h=window.innerHeight|| document.documentElement.clientHeight|| document.body.clientHeight;
History Object
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.
History Object Properties:
History Object Method:
Example:
history.back()//执行的操作与单击后退按钮执行的操作一样history.go(-2)//执行的操作与单击两次后退按钮执行的操作一样
Location Object
The Location object contains information about the current URL.
Location Object properties:
Location Object method:
Window Object method
Alert () Displays a warning box with a message and a confirmation button.
Blur () Moves the keyboard focus away from the top-level window.
Close () Closes the browser window.
Focus () gives the keyboard focus to a window.
Moveby () Moves the specified pixel relative to the current coordinates of the window.
MoveTo () moves the upper-left corner of the window to a specified coordinate.
Example:
window.moveTo(50,50);
Open () Opens a new browser window or looks for a named window.
Example:
var a=window.open(‘‘,‘‘,‘width=200,height=100‘);
Prompt () Displays a dialog box to prompt the user for input.
Resizeby () Resizes the window according to the specified pixel size.
Resizeto () Adjusts the size of the window to the specified width and height.
Scrollby () Scrolls the content by the specified pixel value.
Example:
function fn2(){scrollBy(0,200);//可以用它来滚动到指定内容 }
ScrollTo () Scrolls the content to the specified coordinates.
Example:
function fn1(){scrollTo(0,0);//可以用它来回到顶部 }
SetInterval () invokes a function or evaluates an expression by the specified period (in milliseconds).
Example
function show(){alert(‘a‘);}setInterval(show, 1000);
SetTimeout () invokes a function or evaluates an expression after the specified number of milliseconds.
Example
timer=setTimeout("fn3()",100);
Clearinterval () cancels the timeout set by SetInterval ().
Cleartimeout () cancels the timeout set by the SetTimeout () method.
Example
clearTimeout(timer);
Browser Object Model BOM