Js learning notes (11) window and framework

Source: Internet
Author: User

Properties of the window object (note that window represents the window)

For more information about the window attribute, seeHttp: // 221.199.150.103/jsj/Html/page/book/js/d_1_1_htm? F = 14, L = 1

Window. closed // a Boolean value. Its value is true only when the window is closed.

Window. defaultStatus // set or return the default text in the window status bar. This attribute is readable and writable. FF browser does not support this attribute

Window. frames [] // frames [] is an array composed of all the named frames in the window. Each element of this array is a Window object, which corresponds to a frame in the Window. Each frame defined by <frameset> and <iframe> in the browser Window is an element in the frames [] array, note: The frames [] array element can also have a framework, so frames [I] can have its own frames [] array.

Window. opener // return the reference of the Window object created in this window, which means Window. opener is in. used in a new window created or opened by open (), which references window. the window object in open (), so the window. opener provides a method to link two windows. However, if the new window is not created by window. open () is opened manually by the user, then the window. the opener value is null. note: Only the operner attribute of the Window object in the top-level Window is valid, indicating that the operner attribute of the Window object in the framework is invalid.

Window. self // references the current window itself. window, self, and window. self are equivalent.

Window. parent // references the parent window of the current window. If the window itself is a top-level window without a parent window, the parent attribute returns a reference to itself.

Window. top // reference to the top-level window. If the current window is the top-level window, top returns a reference to itself. Note: Sometimes the top-level window is different from the parent window.

A code that prevents others from referencing their own web pages using a framework:

If (window! = Top) {top. location = window. location ;}

 

Sub-object of the window object

Window. historyAn object is composed of a series of URLs. These URLs are the URLs that you have accessed in a browser window. The History object was originally designed to indicate the browsing History of the window. However, for privacy reasons, the History Object no longer allows scripts to access actual URLs that have already been accessed. Only the back (), forward (), and go () methods are supported.

Window. history. length // returns the number of elements in the browser history list.

Window. history. back () // load the previous URL in the history List (equivalent to the button for the back function in the browser)

Window. history. forward () // load the next URL in the history List (forward)

Window. history. go () // load a specific page in the history list

Window. locationThe object contains the URL Information of the document currently displayed in the window. If you assign a URL string to the Location object or its href attribute, the browser will load the document referred to by the new URL and display it. We can also use the Location object property to modify some URLs so that a new URL will be created. Some of them are different from the original URL, and the browser will load and display it.

Window. location. href // set or return the complete url

Window. location. protocol // set or return the protocol of the current URL

Window. location. host // set or return the host Name of the current url and the port number of the current URL.

Window. location. hostname // set or return the current url Host Name

Window. location. port // set or return the port number of the current url

Window. location. pathname // set or return the path section of the current url, for example, the path field in "http://www.123.com: 2700/example/test.htm # part2" is "/example/test.htm ".

Window. location. search // set or return the question mark (?) The starting URL (query part) such as: "http://www.123.com: 2700/example/test.htm? K = 5 # the query section in part2 is "? K = 5 ".

Window. location. hash // you can set or return the URL (Anchor) starting from)

---------------- Method -------------------

Window. location. assign (url) // loads the specified url document. The url parameter is a string. This method is equivalent to window. location. href.

Window. location. reload () // reload the current l document

Window. location. replace (url) // load a new document to replace the current l document. The url parameter is a string. Note: The replace () method does not generate a new record in the History object. When this method is used, the new URL will overwrite the current record in the History object.

 

Window. navigatorThe object contains information about the client browser.

Window. navigator. appVersion // return the browser version number and other information. Note that this should be regarded as an internal version number because it is not always the same as the version number displayed to the user.

Window. navigator. appName // return the browser name

Window. navigator. platform // return the hardware platform that runs the browser

Window. navigator. userAgent // return the value of the user proxy header used by the browser for HTTP requests. The content is similar to window. navigator. appVersion.

Window. navigator. screenThe object provides information about the user's display size and available color quantity.

Window. screen. width // return the display width in pixels.

Window. screen. height // return the height of the display, in pixels

Window. screen. availWidth // return the available width of the display, in pixels, which is usually the same as window. screen. width.

Window. screen. availHeight // return the available height of the monitor, excluding the taskbar

 

Window object Method

Window. open ()

Window. closed ()

Alert (), confirm (), prompt ()

Focus (), blur ()

SetInterval (), clearInterval (), setTimeout (), clearTimeout ()

Print ()

ResizeTo (width, height) // adjust the window to the specified size

ResizeBy (width, height) // increase or decrease the specified width or height of the window. The two parameters can be positive or negative.

MoveTo (x, y) // move the window to the specified Coordinate

MoveBy (x, y) // move the window to the specified distance in the x or y directions. The two parameters can be positive or negative.

ScrollTo (xpos, ypos) // scroll the window document to the specified place

ScrollBy (xpos, ypos) // scroll the window document to a specified distance

 

Framework

Each window object has a frames [] array to reference its contained framework. Note: If a window does not contain any other framework, the frames [] array of the window is empty, the use of frames [] arrays only applies when a frame exists in a window, such as window. frames [0] indicates the reference of the window to the first framework contained in it, window. frames [0]. frames [0] indicates a reference to the nested framework.

If you specify the framework name (its name attribute), the reference to that framework will be stored in a new attribute of its parent window object, the new property name is the same as the framework name, so you can use window. the framework name references a framework. Note that the window and framework here can only be a parent-child relationship, but not a parent-child relationship.

A function is executed in the scope that defines it, rather than in the scope that calls it,For example, function f () is defined in framework A. If it is called in framework B, the runtime environment of the function is equivalent to in framework A. If function f () if global variables are referenced in framework A, they are searched for in framework A, rather than in framework B.

Variables and functions in different frameworks can be called by different frameworks.

 

Error Handling

The onerror attribute of the window object is special. If a function is assigned to this attribute, the function will be called as long as a javascript error occurs in the window, at this time, the system will pass three parameters to the function. The first parameter is the message describing the error, and the second parameter is a string, which stores the URL of the document where the code that causes the javascript error is located, the third parameter is the line code with errors in the document.

If true is returned to the onerror attribute, no error prompt box is displayed even if an error occurs.

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.