JavaScript reference tutorial
By Micro
Document object
Now we will start discussing more "actual" topics - document objects (DOM). Document object refers to an object that is divided in the web document. There is a few "big" objects in JavaScript: Window, Document, Location, Navigator, Screen, History, etc. Below is a document object tree, you can see the "spectacular" scenario containing the object under the object. To reference an object, you have to list the parent's objects. For example, to reference a text box "CustomerName" of a form "ApplicationForm", you must use "Document.Applicationform.customername".
Some objects in the table below are all written, and some are beginning to uppercase letters. Subjects at uppercase letters, reference to this object does not use the name listed in the table, and directly use the "name" of the object (ID or Name, which is explained below), or specify the object array of object it belong.
Here we are not prepared to explain the "event" of the object, although we will also list the events that can respond to the object. We will explain the event in the next chapter "Event Process".
Navigator Screen WinDow
History location frames []; frame document
ANCHORS []; links []; link applets [] embeds [] forms []; form
Button Checkbox Elements []; Element Hidden Password Radio RESET SELECT
Options []; option submit text textarea images []; Image Browser Object Screen Object Window Object History Address Object Frame Object Document Object Connection Objects Java Small User Object Plugin Object Form Object Button Object Check Box Object Form Element Object Hide Object Password Input Area Object Single Domain Object Reset Button Object Select Zone (drop-down menu, list) Object selection object Submit button object text box object Multi-line text input area object picture object
The Navigator browser object reflects the information of the currently used browser.
Attributes
AppCodename Returns the "Code" (?) of the browser (?), popular IE and NN return 'Mozilla'. AppName returns the browser name. IE returns 'Microsoft Internet Explorer', NN returns 'Netscape'. AppVersion returns the browser version, including the large version number, small version number, language, operational platform and other information. Platform returns the action platform of the browser, returns 'Win32' on the browser on Windows 9x (case of case where cases may be different). UseERAGENT returns all the above information. For example, IE 5.01 returns 'mozilla / 4.0 (compatible; msie 5.01; windows 98)'. JavaEnabled () returns a Boolean value that represents the current browser allows Java to be allowed.
The Screen screen object reflects the current user's screen settings.
Attributes
Width returns the width of the screen (the number of pixels). Height returns the height of the screen. AvailWidth returns the available width of the screen (removed some of the widths occupied by something that do not automatically hide the similar taskbar). AvailHeight Returns the available height of the screen. ColorDepth Returns the number of bits used in the current color settings - 1: black and white; 8: 256 colors; 16: Enhance color; 24/32: True color Window window object's largest object, it describes a browser window. When it is generally referenced to its properties and methods, it is not necessary to use "Window.xxx" in the form of "XXX" directly. A framework page is also a window.
Attributes
The name of the Name window, the open () method called by opening its connection () or frame page ( tag: " Close window ". Parent Returns the frame page object to which the window belongs. TOP returns the top of the entire browser window to the top page object. History historical object, see below. Location address object, see below. Document document object, see below.
method
Open () opens a window. Usage: OPEN (
Example: Open a clean window 400 x 100: open ('', '_ blank', 'width = 400, height = 100, menubar = no, toolbar = no, location = no, directories = no, status = no, Scrollbars = yes, resizable = yes') Parameters TOP = # Window top Level of pixels at the top of the screen Left = # Window left left side left the left-left pixel number width = # window Width = # Window high menubar = ... window Is there a menu, value Yes or NOTOOLBAR = ... window has a toolbar, values YES or NOLOCATION = ... Window has an address bar, value Yes or Nodirectories = ... window has a connection area, take Value Yes or Noscrollbars = ... window has no scroll bar, value YES or NOSTATUS = ... window There is no status bar, value Yes or NORSIZABLE = ... window does not adjust the size, value Yes or NO
The OPEN () method has a return value, returning is the window object it open. and so,
Var newWindow = Open ('', '_ blank');
This assigns a new window to the "NewWindow" variable, and then control the window through the "newWindow" variable.
Close () Close an open window. Usage: Window.close () or Self.close (): Close this window;
OnLoad; OnResize; Onfocus; OneRror
History historical object history object refers to the browser browsing history. In view of the safety needs, the object receives a lot of restrictions, and now only the following properties and methods remain.
Attributes
Length history of history. History that JavaScript can manage is limited to the range of "advancement" "back" keys in the browser. This attribute returns the sum of the number of addresses included under "advancement" and "back" two buttons.
method
Back () back, follow the "Back" button is equivalent. Forward () advance, follow the "advance" button is equivalent. Go () usage: History.go (x); go to the specified address within the scope of history. If x <0, return X address, if x> 0, then forward X addresses, if x == 0, refresh the top now open. History.go (0) is equivalent to location.Reload (). Location Address Objects It describes the address opened by a window object. To indicate the address of the current window, just use "location" to do it; if you want to indicate the address of a window, use "
Note that the two addresses belonging to different protocols or different hosts cannot be referenced to each other's Location objects, which is for security needs. For example, the current window opens "www.a.com", another window (object name: bwindow) opens "www.b.com" webpage. If you use "bwindow.location" in the current window, it will be wrong: "No Permissions". This error is to receive processing with the error handler (Event Handler, see the OneRror event).
Attributes
Protocol Returns the protocol of the address, with the value of 'http:', 'https:', 'file:', and so on. Hostname returns the host name of the address, for example, an address of "http://www.microsoft.com/china/", location.hostname == 'www.microsoft.com'. Port number of port returns the address, the general HTTP port number is '80'. Host returns host name and port number, such as: 'www.a.com: 8080'. Pathname Returns the path name, such as "http://www.a.com/b/c.html" ,location.pathname == 'b / c.html'. Hash returns "#" and later, such as "http://www.a.com/b/c.html#chapter4" ,location.hash == '# chapter4'; if there is no" # "in the address, Return to the empty string. Search returns "?" and later content, such as "http://www.a.com/b/c.asp?selection=3&jumpto=4" ,location.search == '? Selection = 3 & jumpto = 4'; if If there is no "?" In the address, it returns an empty string. HREF returns all the above content, that is, returns the entire address. How to display it on the address bar of the browser to return. If you want a window object to open an address, you can use "location.href = '...'", you can also use "location = '...'" to achieve this purpose.
method
Reload () is equivalent to "Refresh" or "Netscape" button on your browser. Replace () opens a URL and replaces the address of the current location in the historical object. After opening a URL with this method, press the "Back" button of the browser will not return to the page you just. Frames []; Frame Framework See "Use Framework and Cookies" chapter.
Document Document Object Describes the documentation of the current window or specifying a window object. It contains the content from
to body>. Usage: Document (Current Window) orAttributes
Cookie For cookies, please refer to Chapter of "Use Framework and Cookies". LastModified Current Date of Documentation is a Date object. Referrer If the current document is opened by clicking on the connection, ReferR returns the original URL. Title refers to the text of
method
Open () opens a document so that JavaScript writes data to the current location of the document (refers to the location of JavaScript). Usually do not need this method, JavaScript is automatically called when needed. Write (); Writeln () writes data to the document, and the writes are handled as a standard document HTML. The difference between Writeln () and Write () is that Writeln () will add a wrap after writing data. This wrap is only in HTML, and the specific situation can be unable to be displayed, and the location of the JavaScript is inserted. If inserted into the
mark, this wrap will also be embodied in the document. Clear () Clears the current document. Close () Close the document and stop writing data. If the Write [Ln] () or CLEAR () method is used, you must use a close () method to ensure that the changes made can be displayed. If the document has not fully read, that is, JavaScript is inserted in the document, so it is not necessary to use this method.Now we have enough knowledge to do the following, some of the pop-up updates are notified.