The JS child window refreshes the parent window and the parent window's interaction with the child window

Source: Internet
Author: User

Floating layer embedded IFRAME and Frame Collection window, multiple methods to refresh the parent page

JS Code

The code is as follows Copy Code

<script language=javascript>
Parent.location.reload ();
</script>


Popup child page

JS Code

The code is as follows Copy Code
<script language=javascript>
Window.opener.location.reload ();
</script>


child window refreshes parent window

JS Code

The code is as follows Copy Code
<script language=javascript>
Self.opener.location.reload ();
</script>

Instance

Need to edit the information in the newly opened window, and so on, you need to close the current window and refresh the parent window, so that the changes take effect, this article is about using JavaScript to implement "update records after the child window and refresh the parent window."


Refreshes the parent window and closes the current window

Parent Window Code:

The code is as follows Copy Code

<a href= "javascript:void (0)" onclick= "window.open (' child.html ', ' child ', ' width=400,height=300,left=200,top= 200 '); " > Open child windows </a>

child Window Code:

  code is as follows copy code

<script Language= "JavaScript" type= "Text/javascript" >
<!--
function refreshparent () {    
Window.opener.location.href = window.opener.location.href;    
if ( Window.opener.progressWindow)     
{        
Window.opener.progressWindow.close ();    
}    
Window.close ();}
//-->
</script>  
<a href= "javascript:void (0)" onclick= "Refreshparent ()" > Refreshes the parent window and closes the current window </a>


Refreshing a window opened with the open () method

JS Code

The code is as follows Copy Code
<script language=javascript>
Window.opener.location.href=window.opener.location.href;
</script>

Refreshing a window opened with the Winodw.showmodeldialog () method

Java code

The code is as follows Copy Code

<script language= "JavaScript" >
Window.parent.dialogArguments.document.execCommand (' Refresh ');
</script>


to summarize some of the above methods, let's do an example .

Interaction between parent window and child window in Javascript

We need to interact in the parent and child windows, such as uploading files in a child window, and returning the uploaded results to the parent window. This article is about a simple interaction instance. If your mind is flexible enough

The code is as follows Copy Code

<script type= "Text/javascript" >
<!--
function Openwindow ()
{
NewWindow = window.open (', ' newwindow ', ' Height=300,width=300,scrollbars=auto ');
if (NewWindow!= null)
{
var windowhtml= "windowhtml + = "<body>

windowhtml = "This is the child window!windowhtml + + <input type= ' button ' value= ' sets the background of the parent window to red ' onclick= ' Window.opener.document.body.style.backgroundcolor= "Red"; '/><br> ';
windowhtml + = "<br ><input type= ' button ' value= ' Close ' onclick= ' self.close (); '/> ';
windowhtml = "</form></div></body>
NewWindow.document.write (windowhtml);
Newwindow.focus ();
}
}
-->
</script>

<input value= ' open child window ' onclick= ' Openwindow (); "type=" button ">
<input type=" button "value=" sets the background of the child window to blue " Onclick= ' if (window.newwindow) {newwindow.document.bgcolor= ' blue '; Newwindow.focus ();} '/>

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.