a.html:
<form name="form1" method="post" action=""><a href="javascript:void(null)" onClick="open('b.html','','resizable=1,scrollbars=1,status=no,toolbar=no,menu=no,width=500,height=400,left=150,top=50')">Add</a><input type="text" name="text1"></form>b.html:
<script language="javascript" type="text/javascript">function returnValue(){window.opener.document.all.text1.value=document.getElementById("returnText").value;window.close();}</script> <input type="button" name="Submit" value="submit" onclick="returnValue();"> <input name="returnText" type="text" id="returnText"></p>Supplement: Usage of window.opener
In general, the usage of window.opener is only used to solve the problem that the pop-up window is not prompted when closing a window, but the deeper understanding of it is generally less. In fact, window.opener refers to the window that calls the window.open method.
It is mainly used to solve partial submissions in work. This kind of page spread is very helpful for work.
If you open a page in the main window and want the main window to refresh, use this, the window.opener that opens the page is equivalent to
The window of the main window.
You can use the refresh of the main window
window.opener.location.reload();
If you use a virtual directory: such as struts*.do, you will prompt you to try again
You can change it to window.opener.yourformname.submit()
That's fine
2〉
There is such a situation in the application,
Open window B in window A, close window B after operation in window B, and automatically refresh window A
function closeWin(){hasClosed = true;window.opener.location="javascript:reloadPage();";window.close();}function window.onbeforeunload(){if(!hasClosed){window.opener.location="javascript:reloadPage();";}}</script>The above code will prompt an error when closing window B, saying that Object is missing, and the correct code is as follows:
function closeWin(){hasClosed = true;window.opener.location="javascript:reloadPage();";window.opener=null;window.close();}function window.onbeforeunload(){if(!hasClosed){//If the closeWin method has been executed, this method is not executed window.opener.location="javascript:reloadPage();";}}</script>reloadPage method is as follows:function reloadPage() {history.go(0);document.execCommand("refresh")document.location = document.location;document.location.reload();}PS: Since it is necessary to support the normal closing and forced closing of the window, the global variable hasClosed is used.
===============================================================
In addition, problems will occur when refreshing the parent window when the parent window is a frame:
The page cannot be refreshed without resending the information.
The following modifications are as follows:
window.opener.parent.document.frames.item('mainFrame').location.href = window.opener.location.href;
There is no need to execute the built-in reload() method. Be careful not to add this sentence:
window.opener.parent.document.frames.item('mainFrame').location.reload();
============================================================================================================================
Finally, in order to support refreshing both the normal parent window and the frame parent window, the code is as follows:
function closeWin() {hasClosed = true;<%if(null != frame){%>window.opener.parent.document.frames.item('mainFrame').location.href = window.opener.location.href;<%}else{%>window.opener.location = "javascript:reloadPage();";<%}%>//window.opener.top.mainFrame.location="javascript:reloadPage();";//self.opener.frames.mainFrame.location.reload(true);window.opener = null;window.close();}function window.onbeforeunload(){if (!hasClosed) {<%if(null != frame){%>window.opener.parent.document.frames.item('mainFrame').location.href = window.opener.location.href;<%}else{%>window.opener.location = "javascript:reloadPage();";<%}%>window.opener = null;}}How to use window.opener
window.opener returns a reference to the window that creates the current window, for example, clicking a link on a.htm and opening b.htm. Then we plan to enter a value on b.htm and then assign it to a textbox with id "name" on a.htm, and then write it as:
window.opener.document.getElementById("name").value = "Input data";
There is no good understanding of window.opener in javascript.
Why can't it be used in the frame? The parent window of the pop-up window cannot be on a certain page in the frame? So how do you operate the parent window in the frame through a pop-up window?
opener.parent.frames['frameName'].document.all.input1.value Try this :)
If you want to change the page in the frame frame to other pages under the same frame or pages in the parent frame, use parent
window.opener refers to the parent page of the page opened by window.open.
The window.frames object can refer to the page in the iframe or the page in the frameset.
Can
window.frames[0].document.getElementById('xx');
Can
window.frames[0].document.body.innerHTML;
frm = window.parent.window.frames['uploadFrame'];
frmDocument = frm.document;
frm.sb(3); //sb is a function in the uploadFrame page
For firefox
If you encounter an error: parent.document.frames has no properties
Just change to the following code. This code is compatible with IE and ff. frm = window.parent.window.frames['uploadFrame']; In fact, the frames collection is not hung in the document but in the window object.
Note that there are restrictions on modifying the page in the frame in this way, that is, it must be in the same domain, otherwise it will not be accessible.
If it is under the same domain but the subdomain names are different, then add a sentence to the js and html files involved.
document.domain = xxx.com [Fill in your domain name here] document.getElementById('iframeid').contentWindow.document.getElementById('someelementid');
ask:
In the parent window window.open() a child window. and define a variable i.
Enter a value j in the child window and window.opener.i=j;
This way it can pass. But I added window.close() at the end of the child window and couldn't pass the value.
Is there a way to solve this problem? Make me pass the value before closing the child window.
The code is as follows:
Parent window: parent.jsp
<script>var i;window.open('<%=contextPath%>/usermanage/newscontrol/cd.jsp);</script><input type="button" onclick="alert(i)">Sub-window:cd.jsp
<script>function subm(){window.opener.i=5;window.close();}</script><input type="button" onclick="subm()">1 Answer
You can put one in the parent window
<input id="fromChild" type="hidden" /><input type="button"onclick="alert(document.getElementById('fromChild').value)">In the child window:
function subm(){window.opener.document.getElementById('fromChild').value=5;window.close();}This is OK
<head><script language=javascript>function windowclose(){ window.opener=null;window.close();}</script></head><body><input id="Button1" type="button" value="button" onclick="windowclose()" /></body>The above simple example of the return value of the js pop-up window is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.