Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As per <a href="http://www.codehappiness.com/post/access-parent-window-from-child-window-or-access-child-window-from-parent-window-using-javascript.aspx" rel="nofollow">code happiness</a></p> <p>In JavaScript, the window.opener object can be used to access the HTML elements present in the parent window from child window(popup or similar).</p> <p>Let us consider two HTML files:</p> <p>openwindow.htm – this has a text box and a button, clicking the button opens the target.htm file in a new browser window target.htm – this has code to change the value of the text box present in the parent window(openwindow.htm) that opens this file</p> <pre><code>openwindow.htm: (parent window) &lt;html&gt; &lt;script language="javascript"&gt; function openwindow() { window.open("target.htm","_blank","height=200,width=400, status=yes,toolbar=no,menubar=no,location=no") } &lt;/script&gt; &lt;body&gt; &lt;form name=frm&gt; &lt;input id=text1 type=text&gt; &lt;input type=button onclick="javascript:openwindow()" value="Open window.."&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If you are not familiar with window.open() method, then you would be wondering what is "height=200, width=400, status=yes, toolbar=no, menubar=no, location=no", don’t worry, it just specifies the size and appearance of the new window, this line of code can be changed to window.open("target.htm","_blank") just see the difference in output if you change.</p> <p>Note that if the parameter ”_blank” is not provided then the functionality will differ between IE and Firefox, in firefox a new tab will be opened instead of a new window. Just use window.open("target.htm") and see the difference yourself. For more info about window.open() method and its parameters, see <a href="http://msdn2.microsoft.com/en-us/library/ms536651(VS.85).aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms536651(VS.85).aspx</a>. Also note, in , the id attribute is necessary, then only the code of target.htm(shown below) will execute in Firefox.</p> <pre><code>target.htm: (child window) &lt;html&gt; &lt;script language="javascript"&gt; function changeparent() { window.opener.document.getElementById('text1').value="Value changed.." } &lt;/script&gt; &lt;body&gt; &lt;form&gt; &lt;input type=button onclick="javascript:changeparent()" value="Change opener's textbox's value.."&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Hope you can get what is going on in the above code, in the new window(target.htm) we are using the window.opener object to access the text box present in the parent window(openwindow.htm). You just need to prefix “window.opener.” and write the same code that you will write in the parent window’s HTML page to access its elements.</p> <p><strong>Updated Answer</strong></p> <pre><code>1. Put a hidden field on the child page. &lt;asp:HiddenField ID="hidChild" runat="server"/&gt; 2. in your javascript function var childHidden = document.getElementById('&lt;%hidChild.ClientID%&gt;'); childHidden.value = window.opener.document.getElementById('text1').value; 3. Now access this hidden control on the page load event. Response.Write(hidChild.Value); or Session["ParentVal"] =hidChild.Value; </code></pre> <p>so in this way you will have the parent page value in the page load of child.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload