Parent object in JavaScript

Source: Internet
Author: User

The change always refers to the top-level browser window of the split window. If you plan to execute commands from the highest level of the split window, you can use the top variable.

Parent

This variable refers to the parent window that contains the current split window. If you have a split window in one window and a split window in one of the split Windows, the 2nd-tier split window can refer to the parent-partition window that contains it with the master variable.

Opener:

The original window corresponding to a new window created in a window.open manner.

Attachment: Window object, parent object, frame object, Document object, and class relationship of form object: Windwo Object →parent Object →frame Object →document object →form object,

as follows: Parent.frame1.document.forms[0].elements[0].value;

Problem: Embed frame <iframe> in one page, and then use Jvascript script in frame: parent.xx.value= ' xxxxx '; The assignment can be seen normally in IE, but it cannot be done in Firefox. What should be the object that calls the parent frame in Firefox, and whether it is compatible with IE.

Answer: window.parent.document.form name. xx.value= ' xxxxx '; window can be omitted.

Parent.document.form name. xx.value= ' xxxxx '; Parent.document.getElementById ("xx"). value= ' xxxxx ';

The difference between window.parent and Window.opener JavaScript invokes the main window method

1:window.parent is an IFRAME page invoke the parent Page object

Example: a.html

<body>

<form name= "Form1" Id= "Form1" >

<input type= "text" name= "username" id= "username"/>

</form>

<iframe src= "b.html" width=100%></iframe>

</body>

If we need to a.htm in the b.htm of the username text box (such as a lot of upload function, upload function page in Ifrmae, upload a successful post upload path into the text box of the parent page), we should write in the b.html:

<script type= "Text/javascript" >

var _parentwin = window.parent;

_parentwin.form1.username.value = "XXXX";

</script>

2:window.opener is the window.open open subpage Call parent Page object

Opener: A reference to the Window object that opens the current Windows, and its value is null if the current window is opened by the user.

Self: The self-referencing property, which is the application of the current Window object, is synonymous with the Window property.

Self represents its own window, and opener represents the window that opens itself, such as window A, which opens window B. If you rely on the Window.Open method, the window b,self represents B itself, and opener represents window A.


This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/jamestaosh/archive/2009/06/20/4284960.aspx If we need to a.htm in the b.htm of the username text box (such as a lot of upload function, upload the function page in Ifrmae, upload a successful post upload the path into the parent page text box), we should write in the b.html: 2: Window.opener is the window.open open subpage calls the parent Page Object opener: A reference to the Window object that opens the current Windows, and its value is null if the current window is opened by the user. Self: The self-referencing property, which is the application of the current Window object, is synonymous with the Window property. Self represents its own window, and opener represents the window that opens itself, such as window A, which opens window B. If you rely on the Window.Open method, the window b,self represents B itself, and opener represents window A. This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/jamestaosh/archive/2009/06/20/4284960.aspx

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.