Report software JS development location and document objects referencing the HTML DOM

Source: Internet
Author: User
Tags html form

As mentioned last time, the HTML DOM objects that can be accessed and processed in the report software Finereport JavaScript development are Windows, location, document three. This time, we will continue to introduce the latter two types, location and document object.

Location

The Location object contains information about the current URL. The Location object is a part of the Window object that can be accessed through the Window.location property.

Location Common Properties for Objects

Hash set or return URL starting with #

Host sets or returns the hostname and port number of the current URL

Hostname Sets or returns the host name of the current URL

HREF Sets or returns the full URL

Pathname Sets or returns the path portion of the current URL

Port Sets or returns the port number of the current URL

Search to set or return a URL starting from? (Query section)

1.location object's reload () Method

The reload () method is used to reload the current document

The syntax is:

Location.reload (False)

If the method does not specify a parameter, or if the parameter is False, it uses the HTTP header if-modified-since to detect whether the document on the server has changed. If the document has changed, reload () will download the document again. If the document does not change, the method will load the document from the cache. This is exactly the same as when the user clicks the browser's Refresh button.

If the parameter of the method is set to true, it bypasses the cache and re-downloads the document from the server, regardless of the last modification date of the document. This is exactly the same as when the user presses the refresh button of the browser while holding down shift.

Document

Each HTML document that is loaded into the browser becomes the document object. The Document object allows us to access all elements of an HTML page from within a script.

The Document object is part of the Window object and can be accessed through the Window.document property

1.document Common Properties for Objects

Cookie sets or returns all cookies related to the current document

Title returns the caption of the current document

URL returns the URL of the current document

2.document Common methods for objects

2.1 Close () Method

The close () method closes an output stream opened by the Document.open method and displays the selected data. Grammar:

Document.close ()

This method closes the document stream opened by the open () method and forces the output of all caches to be displayed.

If you use the Write () method to output a document dynamically, you must remember to call the close () method when you do so to ensure that all document content is displayed.

Once close () is called, write () should not be called again because it implicitly calls open () to erase the current document and start a new document.

2.2 getElementById () Method

The getElementById () method returns a reference to the first object that owns the specified ID. Grammar:

document.getElementById (ID)


650) this.width=650; "Src=" http://dl2.iteye.com/upload/attachment/0116/9687/ 9a935ba1-0add-39d3-b68e-008bacd6862e.png "style=" border:0px; "/>

Refer to the full code:

2.3 getelemenbyname () Method

The Getelementsbyname () method can return a collection of objects with the specified name.

This method is similar to the getElementById () method, but it queries the element's Name property instead of the id attribute.

Because the Name property in a document may not be unique (such as a radio button in an HTML form typically has the same name property), all Getelementsbyname () methods return an array of elements instead of an element.

The getElementsByTagName () method returns a collection of objects with the specified label name.

The getElementsByTagName () method returns elements in the order that they are in the document.

If you pass the special string "*" to the getElementsByTagName () method, it returns a list of all the elements in the document, the order in which they are arranged in the document.

The string passed to the getElementsByTagName () method can be case insensitive.

2.4write () Method

The write () method writes an HTML expression or JavaScript code to a document. Multiple parameters (Exp1,exp2,exp3,...) can be listed, which are appended sequentially to the document.

Grammar:

document.write (Exp1,exp2,exp3,....)

You typically use the Write () method in two ways:

One is to use this method to output HTML in the document, and the other is to create a new document in a window, frame, outside the window that calls the method.

In the second case, be sure to close the document using the close () method.

Example:


650) this.width=650; "Src=" http://dl2.iteye.com/upload/attachment/0116/9689/ 3c99c972-8e87-35a6-802c-2f14c9ccc67b.png "style=" border:0px; "/>

Reference code:


Report software JS development location and document objects referencing the HTML DOM

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.