JS jquery Closes the popup page and refreshes the parent page (Window.opener)

Source: Internet
Author: User

function Closepage () {    if (Window.opener &&! ) window.opener.closed) {        window.parent.opener.location.reload ();    }     return false ;}

Other ways to learn:

Window.opener usage

Http://www.cnblogs.com/zhangzt/archive/2009/12/24/1631253.html

Window.opener is actually the parent form of a form that is opened through window.open.

For example, in the parent form parentform through window.open ("subform.html"), then Window.opener in subform.html

On behalf of ParentForm, you can set the value of the parent form or call the JS method in this way.

such as: 1,window.opener.test (); ---call the test () method in the parent form

2, if Window.opener exists, set the value of Stockbox in ParentForm.

if (Window.opener &&!window.opener.closed) {

Window.opener.document.parentForm.stockBox.value = symbol;

}

The use of 1>window.opener

In general usage, it is only used to solve the window without prompting the pop-up window, and it is generally less of a deeper understanding. In fact, window.opener refers to the window that invokes the Window.Open method.
In the work is mainly used to solve the partial submissions. This cross-page operation is very helpful to work.
If you open a page in the main window, and you want the main window to refresh, use this, the Window.opener of the open page is equivalent to
Window of the main windows.
Refresh of main window you can use
Window.opener.location.reload ();
If you use a virtual directory: *.do like struts will prompt you to retry

You can change it. Window.opener.yourformname.submit ()
Just fine.

2〉

There is a case in the application that
Open b window in a window, close b window after operation in window B, and refresh a window automatically


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 the error when closing the b window, saying that the 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, do not perform this method
              window.opener.location= "Javascript:reloadpage ();";
        }
    }

</script>
The Reloadpage method is as follows:
function Reloadpage () {
History.go (0);
Document.execcommand ("Refresh")
Document.location = document.location;
Document.location.reload ();
}
PS: The global variable is used when the event is captured due to the need to support graceful shutdown and forced closing of Windows hasclosed

==============================================

Add, the problem occurs when the parent window is refreshed when the parent is a frame:

The page cannot be refreshed without resending the information.
After modification as follows:
Window.opener.parent.document.frames.item (' MainFrame '). Location.href = Window.opener.location.href;
Do not need to implement your own reload () method, note, do not 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;
}
}
About Window.opener

The use of Window.opener

Window.opener returns a reference to the window that created the current window, such as clicking on a link on a.htm and opening the b.htm, and then we're going to enter a value on the b.htm and give it a TextBox with an ID of "name" on the a.htm, It can be written as:

Window.opener.document.getElementById ("name"). Value = "Data entered";

There is no good understanding of the Window.opener in Javascrīpt.

Why can't a pop-up window's parent window have a page in the frame that can't be used? How do you manipulate the parent window in the frame through a popup window?

opener.parent.frames[' FrameName '].document.all.input1.value try this:)

Correct use of window.open returns the opener of an object

It is well known in javascript:

var win = window.open (Url,windowname,...); of use,

And Win.opener is a reference to the parent window

However, there is a very special situation,

If there are two windows Window1 and Window2

Follow these steps:

var win = window.open (Url,windowname,...); /(Window1)

var win = window.open (Url,windowname,...); /(WINDOW2)

One of these two times the windowname of the Open sub-window

At this point you will find that the Win.opener in Window2 is not pointing to window2, but is pointing to Window1.

If you want to close the parent window in a child window, it is not correct, so you can modify the execution method above as follows:

var win = window.open (Url,windowname,...);? (Window1)

Win.opener = window;

var win = window.open (Url,windowname,...);? (WINDOW2)

Win.opener = window;

Only this change is OK


A page that pops up via window.showModalDialog or. showModelessDialog

This situation requires two steps:
1 Pass the Window object in the second argument of the parent window. ShowModalDialog or. showModelessDialog method
For example: Window.showmodelessdialog (' a.htm ', window);
2 This parameter can be obtained by window.dialogarguments in a.htm
For example: Window.dialogArguments.fun1 ();
PS: Child window can be set by setting Window.returnvalue page return value
For example: window.returnvalue= ' OK '; Window.close ();

Strrtn=window.showmodaldialog (...)

At this point, strrtn= ' OK '

Page is implemented in:
Parent page
function Reloadpage () {
Document.form1.submit ();
}
Pop-up page call Closewin ();
function Closewin () {
Hasclosed = true;
Window.opener.location= "Javascript:reloadpage ();";
Window.opener=null;
Window.close ();
}


This article from CSDN Blog: http://blog.csdn.net/zj1103/archive/2009/05/05/4152274.aspx

JS jquery Closes the popup page and refreshes the parent page (Window.opener)

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.