Dom manipulation of JavaScript

Source: Internet
Author: User

1, the basic concept of the DOM

The DOM is the Document Object model, which is a tree model; a document is a label document; An object is a document; A model refers to something that is abstract.

2. Windows object operations one, properties, and methods:

Window Object--browser windows
Window.location: Address bar
Window.history: Access History
Window.status: Status bar
Window.document: Focus!

Property (value or Sub-object):

Opener: Opens the source window of the current window, or opener is null if the current window is open for the first time the browser is started.

Dialogargument: The return value of the dialog box.

Sub-object: History,location,document,status,menubar,toolbar, etc.

Method (function): event (pre-Set program, triggered).

window.open ("Part I", "Part II", "Part Three", "Part IV")

Characteristic parameters of window.open:

The first part: write the page address.

The second part: _blank Open the way, in a new window or its own window.

The third part: Control the Open Window format, you can write multiple, separated by a space as follows:

Toolbar=no the newly opened window has no tool bar;

Menubar=no no menu bar Status=no no status bar;

width=100 height=100 width height;

left=100 Open window distance to the left;

Resizable=no window size is not adjustable;

Scrollbars=yes scroll bar appears;

Location=yes has address bar;

Window.Open also has a return value, and its return value is: The newly opened Window object.

For example:

The simplest open window: window.open ("untitled-6.html");

Open a window and save it in the variable: var w= window.open ();

You can save multiple open windows in the array W:

function Openw ()

{

W[i++]=window.open ();

}

Third, Window.close (): Close the current window;

W.close (): Close the window that is saved in the variable W;

Close multiple child windows: The open window is stored in an array, and the loop is used to turn it off;

Close the source window that opens the current window: Window.opener.close ();

Iv. interval and delay

Interval execution of a piece of code (function): Window.setinterval ("Code to execute", number of milliseconds between intervals)

Cleanup interval execution: window.clearinterval (interval ID); The code that is used to clear the isolated execution after a loop

Delay a period of execution of a piece of code (function): Window.settimeout ("Code to execute", number of milliseconds to delay)

Purge delay: window.cleartimeout (delayed ID); Clear settimeout

Five, adjust the page

Window.navigate ("url") jumps to the target page, there is a bug under Google Chrome;

Window.moveto (x, y) moves the page to a location that is determined by X and y;

Window.resizeto (wide, high) adjusts the width and height of the page;

Window.scrollto (x, Y) scrolls the page to where Y represents the vertical scroll.

Vi. modal dialogs and non-modal dialog boxes

Modal dialog box (Modal dialogue box), which means that the dialog box must first be responded to when the user wants to work with an application other than the dialog box. If you click the OK or Cancel button to close the dialog box, it is always pinned to the non-modal dialog box, and the difference is whether the user is allowed to manipulate other objects while the dialog box is open.

Open Modal Dialog: window.showModalDialog ("url", "Value passed to target dialog box", "window feature parameter");

Feature parameters: separated by semicolons, pixel size with px. Dialogheight,dialogwidth,center, et

Open the Non-modal dialog box: Window.showmodelessdialog ("url", "Value passed to target dialog box", "window feature parameter")

var a = window.dialogargument; You can use a parameter to get the values passed by the modal or non-modal dialog box.

3. Windows.history Object

Window.history.back (); page back;

Window.history.forward (); page forward;

Window.history.go (n); n If a positive number represents the forward n pages, n is a negative number that represents back n pages, which is commonly used.

4. Window.location Object

Location Bar

var s = window.location.href; Gets the address of the current page

Window.location.href= "http://www.baidu.com"; Change page address, jump page

Window.location.hostname: Host name, domain name, site name, available variable receive

Window.location.pathname: path name, available variable receive

5. Window.status Object

Status bar, you can add the text you want to display to the status bar

Window.status= "What to display in the status bar"; Set the status bar text

For example:

function S () {window.status = "go ahead and walk like this";}

Add:

The difference between the carriage return/R and the newline character/n:/R equals Enter, which is the difference between a paragraph and a paragraph.

/n is equivalent to Shift+enter, which is the distance between rows and rows, smaller than

Several window operation methods:

1. Get the current window size and print:

var Height=window.innerheight;var width = window.innerwidth;document.write ("<br/>" + "height" +height+ ", width" + width);

2. Open the window, close the current window

window.open ("http://baidu.com"); Window.close ();

3. Move the current window to a location (x, y)

Window.moveto (200,200);

4. Change the size of the current window (width,height)

Window.resizeto (1100,1100);

5. Get the current page address

document.write (LOCATION.HREF);

Dom manipulation of JavaScript

Related Article

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.