JavaScript Window object

Source: Internet
Author: User

1, settimeout and setinterval

/*arranges the function f (), which is called after a number of milliseconds after waiting for the next call F () if the function parameter is not interval, then only F () is called once if the function parameter is set interval, no end is set, then f () will not stop if the function parameter Number is set interval, and end is set, the call F () stops after end milliseconds only when F () is specified, starting from start=0*/functionInvote (f,start,interval,end) {if(!start) Start = 0; if(Arguments.length <= 2) {setTimeout (F,start); }Else{setTimeout (Repeat,start); functionrepeat () {varh =setinterval (F,interval); if(end) {SetTimeout (function() {clearinterval (h);            },end); }        }    }}

2. Browser positioning and navigation
The property of the location of the Window object refers to the position object, which represents the URL of the document that the current window displays.
The Location property of the object of the document is also the referenced location object.
window.location = = = Document.location//true
The object properties of the location are href,protocol,host,hostname,port,portname and search, each representing the parts of the URL.
The hash and search for the location object represents the fragment identifier in the URL.
Search returns the URL after the?
Example:
Extract the parameters of the search string in the URL

functionUrlargs () {varargs = {}; varQueryString = window.location.search.substring (1); varPars = Querystring.split (' & '));  for(vari=0;i<pars.length;i++){        varpos = pars[i].indexof (' = ')); if(pos = =-1) {Continue;} varName = pars[i].substring (0, POS); varValue = pars[i].substring (pos+1); Args[name]=value; }    returnargs;}


3. Loading documents
The Assign () method of the location allows the window to load and display the specified url,replace with similar functionality, but replace deletes the current browsing history!
In addition to the Replace and assign methods, there is one way to reload () to reload the current document!
The most traditional way to make a browser load a new page is
Location = ' http://www.baidu.com ';
If the location is set to a fragment identifier, for example:
Location = ' #top ';
If there is no element with the top ID in the current document, it jumps to the top of the current document! Jumps to the location of the ID specified by the current document if there is one!
4. Browsing History
The History property of the Window object refers to the browser's historical object, which is used to display the browser record of the current window as a list!
history.length;//represents the length of the current browser's history!
The back () and forward () of the history object represent the Historical rewind button!
The third method go (), passing in an integer can go forward and back any length of history in the History list!
If the window contains a child window iframe time! Its browsing history is interspersed in the parent window's historical record and sorted by time! This can sometimes lead to a call to the main window
The way forward and backward causes the URL of the child window to go back to the previous address, and the main window will not change!
5. Navigator Object
AppName://web browser full name
AppVersion://Web browser version information
UserAgent://The string that the browser sends on the User-agent HTTP header
Platform://Name of the operating system on which it is running
For example: Google Chrome
Navigator.appname
"Netscape"
Navigator.appversion
"5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/43.0.2357.132 safari/537.36 "
Navigator.useragent
"mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/43.0.2357.132 safari/537.36 "
Navigator.platform
"Win32"
6. Relationships between Forms
If a form is contained in another form and the latter is included in the top-level form, the form can use Parent.parent to refer to the top-level window! The top property is a generic
Shortcut, regardless of whether a form is nested in several layers, its top property points to the top-level window that contains it.
If there is an iframe window in a page:
For example:
<iframe id= "F1" src= "" ></iframe>
var iframecontent = document.getElementById ("F1");
var Childcon = iframecontent.contentwindow;//The object of the subform
The Window object has a frames property that is a reference to the class array and can be indexed by numbers and names.
For example:
First form: frames[0];
A third form that references the first form
FRAMES[0].FRAMES[2];
Frames[] Array object refers to a Window object instead of a Frame Object!
In addition to being able to reference with a numeric reference and an ID or name
frames[' F1 ') or FRAMES.F1

JavaScript Window object

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.