JavaScript authoritative design--window object iframe (brief study note 14)

Source: Internet
Author: User

document Element (ID) for 1.Window object PropertiesIf an id attribute is used in an HTML document to name an element, and if the Window object does not have a property of that name, the window object is given a property whose name is the value of the ID property, and their value points to the HtmlElement object that represents the document element. The window object exists at the top of the scope chain as a global object, which means that the id attribute used in the HTML document becomes a global variable that can be accessed by the script. such as:
<id= "but"/>
You can refer to this element by using the global variable, but. 2. Multi-Form window (IFRAME)Unlike tabs that are separate from each other, nested browsing contexts are not independent of each other, in a formThe JavaScript program that runs in is always visible to its ancestor and descendant forms. Although the script looks at the documents in these formssubject to the same-origin policy. similar to a Web page in which one or more <iframe> are nested, the interaction between these multiple iframe. A:window.open (url,name,features,replace) is the third parameter:Example:
<HTML> <Head> <Scripttype= "Text/javascript"> functionOpen_win () {window.open ("http://www.baidul.com","_blank","Toolbar=yes, Location=yes, Directories=no, Status=no, Menubar=yes, Scrollbars=yes, Resizable=no, Copyhistory=yes, width=400, height=400") } </Script> </Head> <Body> <form> <inputtype= "button"value= "open Window"onclick= "Open_win ()"> </form> </Body> </HTML>
window Name: window.open () loads the developed URL into a new or existing window, and returns the Window object that represents it. It is important to note that the script is unable to manipulate the window's Web application by the name of the simple Guess window, which is only possible if the "Allow navigation" page is set. simply put, a script can only make a window that exists by name only if the window contains a document from the same source or if the script opens that window . Also, if one of the Windows is a form embedded in another window, you can navigate between their scripts. You can use the reserved word "_top" (the top-level ancestor window), "_parent" (The Direct parent window) to get to each other's browsing context. the method of the Window object, open (), returns the Window object that represents the newly created windows. And the Heart window has the opener property, which can open its original window. such as:
// window.open () is on the page zqz_1.html, var w=window.open (' zqz_2.html ');
// Open a new window zqz_2.html w.open (). opener===W
// which is what opener refers to is zqz_1.html
b: Nested iframe If a window is a top-level window or label, then
// only the top-level window will also return True
If a window is contained in a window window, then parent.parenT to reference the top-level windowwhether a form is nested in layers, use top to return to the top-level window directly. See figure 1,2,3,4A Web page is nested with an IFRAME, the id= ' zqz_2 ' of the IFRAME, which means that the object of the element is:
var zqz_2=document.getelementbyid (' zqz_2 ');
The <iframe> element has the Contentwindow property, which refers to the Window object of the form, so the form object is:
var zqz_2=document.getelementbyid (' zqz_2 '). Contentwindow;
each Window object has a frames property that refers to the child window of the form it contains. The Frames property is a class array object. Class Array object we said before. So it can be obtained by index, i.e.:frames[0]. Use parent.frames[1] to refer to the sibling form. Note : The element in the frames[] array is the Window object, not the <iframe> element. If you specify the name of the <iframe> element, you can also index it by name. such as:frames["zqz_2") or frames.zqz_2 for a form, the <iframe> referenced by the properties of the Window object refers to the Window object in the form, not the element object. The HTML5 specification states that the Frames property is a self-referencing property, and that the Window object looks like an array of forms. That is, you can get a reference to the first subform through window[0] . Window.length. 3. Multi-form interactiondirectly on the example: the parent invokes the child, the child calls the parent, and the child invokes the child. zqz.html (father)
<!DOCTYPE HTML> <HTML> <HeadLang= "en"> <MetaCharSet= "UTF-8"> <title>ZQZ</title> <style> </style> </Head> <Body> <iframesrc= "zqz_1.html"name= "A"width= "200px"Height= "300px"></iframe> <iframesrc= "zqz_2.html"name= "B"width= "200px"Height= "300px"></iframe> </Body> <Script> //Parent Call Child window.onload=function() {frames. B.A (); Alert (frames. B.B); }; //Child Call Parent functionC () {Alert ("Child Call Parent Method C ()"); } varD="Child Call parent variable D"; </Script> </HTML>

Zqz_1.html (son)

<!DOCTYPE HTML> <HTML> <HeadLang= "en"> <MetaCharSet= "UTF-8"> <title>Zqz_1</title> </Head> <Bodybgcolor= "#a52a2a">A</Body> <Script> //Child Call Child varI=1; alert (WINDOW.I);//I this global variable is a property of the global object and a property of the Window object. So you can call it that way . functionA () {alert ("the function A in a is called"); } </Script> </HTML>

Zqz_2.html (son)

<!DOCTYPE HTML> <HTML> <HeadLang= "en"> <MetaCharSet= "UTF-8"> <title>Zqz_2</title> </Head> <Bodybgcolor= "#ff7f50">B</Body> <Script> //Child Call Child Alert (parent. A.I); //Call the global variable I in name= "B" parent. A.A (); //Call a function A () in Name= "B" //Parent Call Child varb="parent invokes child B variable"; functionA () {alert ("The parent invokes the child a method"); } //Child Call Parent parent.c (); alert (PARENT.D);</Script> </HTML>

although function a () in a is called in B above, the scope of a () is still in a. That is, the function executes in the defined domain in which it is defined, rather than in the scope in which it is called.

JavaScript authoritative design--window object iframe (brief study note 14)

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.