Working with Pop Ups and Browser Windows in JavaScript - How to access the data available in main window from within a popup window and vice-versa using JavaScript: discussion
(Page 5 of 5 )
Let us go through some of the important statements in the code I showed you in the previous section. Let us consider the following statement.
w.location.href="HTMLPage7_1.htm";
Until now we have been writing dynamically or passing the URL to the pop up window. The above statement is a bit different. We are trying to change the location (and reload the web page) to which the current pop up window points to. This is another good dynamic way to let the pop up window open another page (without closing the existing pop up).
Further proceeding we have another important statement as follows:
document.all.txtParentName.value = w.document.getElementById
("txtName").value;
According to the above statement, we are trying to retrieve the value available in a text box named "txtName" (which is present in the pop up window) and finally assign the value to another text box named "txtParentName" (which is present in the main window). That means we are trying to transfer the information available in popup window to the main window from within the main window!
Further proceeding we have another important statement as follows:
document.all.txtName.value = opener.document.forms
["form1"].txtParentName.value;
According to the above statement, we are trying to retrieve the value available in a text box named "txtParentName" (which is present in the main window) and finally assign the value to another text box named "txtName" (which is present in the pop up window). That means we are trying to transfer the information available in the main window to the pop up window from within the pop up window!
Further proceeding we have another important statement as follows:
opener.document.forms["form1"].txtParentName.value =
document.all.txtName.value;
According to the above statement, we are trying to retrieve the value available in a text box named "txtName" (which is present in the pop up window) and finally assign the value to another text box named "txtParentName" (which is present in the main window). That means we are trying to transfer the information available in the pop up window to the main window from within the popup window!
The most confusing issue in all the above would be the "opener." That is an object generally available for any pop up window to access the calling window (or main window).
Any comments, suggestions, ideas, improvements, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |