Browser Object Model BOM Summary

Source: Internet
Author: User

BOM
Windows Objects
Document Object
Location Object
Screen Object



Windows Objects

1. Window Operation


move the specified distance: Window.moveby (10,20); Move 10 pixels to the right and move down by 20 pixels
move to the specified position: Window.moveto (x, y);
Modify the window's aspect: Window.resizeby (x, y);
modify aspect to the specified value: Window.resizeto (x, y); Move the window so that its width is adjusted to x, and the height adjusts to Y

(IE)
Get the window from the screen position (left, top):
alert (window.screenleft);
alert (window.screentop);
Customer area aspect:
alert (document.body.offsetWidth);
alert (document.body.offsetHeight);

(Mozila)
Window Position:
alert (Window.screenx);
alert (window.screeny);
Customer area aspect:
alert (window.innerwidth);
alert (window.innerheight);


2. Open the link in a new window (pop-up window)
Windows.open ("URL", "New Window Name", "new Window Feature");

eg.
defines a button that displays the name "Open" and opens a Web page named x.html with a window length of 400px when the mouse is clicked

<input id= "btn" type= "button" value= "Open"/>
<script type = "Text/javascript" >
var btn = document.getElementById ("btn");
Btn.onclick = Functionz () {
Windows.open ("x.html", "", "width=400px, height=400px");
};
</script>



3. System dialog box (control user behavior)
Window.alert ("string"); alert () method

if (Confirm (sure?)) {//Confirm () method
alert ("yes");
}else{
alert ("no");
}

var str = window.prompt ("Please Enter Name:", "Zhang Zhang"); prompt () method
alert (str);

4. Status bar (not professional, annoying users)
window.defaultstatus = "test Data"; Temporarily change the text of the status bar
window.status = "Test"; The text can be changed all the time when the user leaves the current page

5. Time interval and pause (effectively tell the browser when to execute a line of code)

var id=window.settimeout ("Execute Code", (Interval) (milliseconds);
window.cleartimeout (ID);

var id=window.setinterval ("Execution Code", (pause, can not be set) number of milliseconds);
window.clearinterval (ID);

eg.
<input type= "button" id= "BTN" value= "Start"/>
<input type= "text" size= "id=" txt1 "/> "
<input type= "button" id= "btn2" value= "Pause"/>
<script type= "Text/javascript" >
var btn = document.getElementById ("btn");
var btn2 = document.getElementById ("btn2");
var txt = document.getElementById ("Txt1");
var R;
Btn.onclick = function () {
function Test () {
var day = new Date ();
txt.value = day;
r = window.settimeout (test, +);
}
test ();
};

Btn2.onclick = function () {
Window.cleartimeout (r);
};
test ();
</script>


6. History
Window.history.go (-1); Positive front negative, the number is-1 means each back, only one page back
The reference to the//window object is not required, or history.go () can be used;
History.back (); Back
History.forward (); Forward
Number of pages:
alert ("+history.length+" page in history); There are x pages in the history record


Document Object (represents a blank area of the window)

1. Properties
Last Modified date of page (not very useful): Lastmodify
Browse the URL of a location back in history (less useful): referrer
text displayed in the </title> tag (readable and writable): Title
URL of current page (readable/writable): URL
eg.
Alert (document. URL);


2. Collection Properties
collection of all anchor points in the page:anchors
eg.
<style type= "Text/css" >
Div {
height:2000px;
}
</style>

<body>
<a name= "A" href= "#" > Anchor point 1</a>
<a name= "A" href= "#" > Anchor point 2</a>
<a href= "#" > Anchor point 3</a>
<div></div>
<script type= "Text/javascript" >
alert (document.anchors[0].innerhtml);
</script>
<a href= "#a" > Back to Top </a>

Form collection: Forms
Picture collection: Images//Available document.images[0] or document.images["ImageName"]
Hyperlink collection: Links

3. Method (the entire page element will be reset, not easy to use)
write ("");
writeln ("");


Location object (indicating the URL of the loading window)

1. Parsing URLs
Server name: Host
the part after the hostname in the URL: pathname
Port: Prot//Most URLs do not have port information, so they are usually blank
Protocol: Protocol//URL used in the Protocol, before (//) in the section
the part after the question mark in the URL: Search
eg.
alert (location.search);

2. Jump to a new page
location.href= "a.html"
location.assign ("a.html");
location.replace ("a.html"); No historical information

3. Refresh the page
Location.reload (TRUE); Refresh from server
Location.reload (TRUE); Refresh from local

Navigator Object (contains a lot of information about the Web browser)

//Window.navigator Reference It can also be used navigator reference

Save Browser-related information
language
useragent
OnLine

Screen object (get some information about the user's screens)

The height of the screen that the window can use: availheight
The width of the screen that the window can use: availwidth
number of color digits (32-bit for most systems): ColorDepth
screen Height: height
width of screen:

Full Screen
Window.moveto (0,0);
Window.resizeto (screen.availWidth.screen.availHeight);


Browser object Model BOM summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.