function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
s_foos_foo 

close the window after save and refresh parent

I have a jsp page which is opening a apex page in a new window.  when some one clicks save on the apex page, the requirement is to save the changed data , close apex page window and refresh the calling parent.

 

Any help is highly appreciated.

 

P.S. I have tried window.top.close() which closes down the window without saving the data.

 

Thanx

 

S

Best Answer chosen by Admin (Salesforce Developers) 
andresperezandresperez

Hi,

 

This part has to be done in Javascript... with a technique called inter-window communication.

 

Here is a sample of what I'm talking about:

 

Opener page: ( this is the one who calls the window.open(); )

<html> <head> <title>*** OPENER ***</title> </head> <body> <form id="form1" runat="server"> <table border="1"> <tr> <th> Counter: </th> <td> <input type="button" onclick="Count();" value="Count" /><br /> <input type="text" id="ShowCounter" value="0" /> </td> </tr> <tr> <th> Message: </th> <td> <input type="button" onclick="Write();" value="Write" /> <span id="OutMsg">...</span><br /> <input type="text" id="InMsg" value="..." /> </td> </tr> <tr> <th> Other Window: </th> <td> <input type="button" onclick="OpenWindow();" value="Open Window" /><br /> <input type="button" onclick="UpdatePopPup();" value="Update PopUp" /> </td> </tr> </table> </form> </body> </html> <script type="text/javascript" language="javascript"> // Local Scripts function Count() { var objCounter = document.getElementById('showCounter') objCounter.value = ++objCounter.value; } function Write() { WriteMessage(document.getElementById('InMsg').value); } function WriteMessage(inMsg) { var objMsg = document.getElementById('OutMsg'); objMsg.innerHTML = inMsg; } </script> <script type="text/javascript" language="javascript"> // Other window scripts var newWindow = null; function OpenWindow() { newWindow = window.open('page2.aspx'); } function UpdateOpener(txtMsg, txtCounter) { document.getElementById('InMsg').value = txtMsg; document.getElementById('ShowCounter').value = txtCounter; Write(); } function UpdatePopPup() { if (newWindow != null) { Write(); var txtMsg = document.getElementById('InMsg').value; var txtCounter = document.getElementById('ShowCounter').value; newWindow.UpdatePopPup(txtMsg, txtCounter); } } </script>

Pop-up page:

<html> <head> <title>*** POP-UP ***</title> </head> <body> <form id="form1" runat="server"> <table border="1"> <tr> <th> Counter: </th> <td> <input type="button" onclick="Count();" value="Count" /><br /> <input type="text" id="ShowCounter" value="0" /> </td> </tr> <tr> <th> Message: </th> <td> <input type="button" onclick="Write();" value="Write" /> <span id="OutMsg">...</span><br /> <input type="text" id="InMsg" value="..." /> </td> </tr> <tr> <th> Other Window: </th> <td> <input type="button" onclick="CloseWindow();" value="Close Window" /><br /> <input type="button" onclick="UpdateOpener();" value="Update Opener" /> </td> </tr> </table> </form> </body> </html> <script type="text/javascript" language="javascript"> // Local Scripts function Count() { var objCounter = document.getElementById('showCounter') objCounter.value = ++objCounter.value; } function Write() { WriteMessage(document.getElementById('InMsg').value); } function WriteMessage(inMsg) { var objMsg = document.getElementById('OutMsg'); objMsg.innerHTML = inMsg; } </script> <script type="text/javascript" language="javascript"> // Other window scripts function CloseWindow() { window.top.close(); UpdateOpener(); } function UpdateOpener() { if (window.opener != null) { Write(); var txtMsg = document.getElementById('InMsg').value; var txtCounter = document.getElementById('ShowCounter').value; window.opener.UpdateOpener(txtMsg, txtCounter); } } function UpdatePopPup(txtMsg, txtCounter) { document.getElementById('InMsg').value = txtMsg; document.getElementById('ShowCounter').value = txtCounter; Write(); } </script>

 

Hope that helps...

 

All Answers

andresperezandresperez

You could try something like this:

 

<apex:page standardController="Account"> <apex:form > <apex:pageBlock ID="AJAXTest"> <apex:pageBlockSection columns="1"> <apex:inputText value="{!Account.name}" size="120" /> <apex:commandButton action="{!Save}" value="Save"

rerender="AJAXTest" status="AJAXStatus"/> <apex:actionStatus startText="(Saving...)" stopText=""

onStop="window.top.close();" ID="AJAXStatus"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

s_foos_foo

Andrés,

 

Appreciated your help. this solution works for me partly. I mean, it saves the date and closes the window but doesn't refresh my parent.

 

Thanx

 

andresperezandresperez

Hi,

 

This part has to be done in Javascript... with a technique called inter-window communication.

 

Here is a sample of what I'm talking about:

 

Opener page: ( this is the one who calls the window.open(); )

<html> <head> <title>*** OPENER ***</title> </head> <body> <form id="form1" runat="server"> <table border="1"> <tr> <th> Counter: </th> <td> <input type="button" onclick="Count();" value="Count" /><br /> <input type="text" id="ShowCounter" value="0" /> </td> </tr> <tr> <th> Message: </th> <td> <input type="button" onclick="Write();" value="Write" /> <span id="OutMsg">...</span><br /> <input type="text" id="InMsg" value="..." /> </td> </tr> <tr> <th> Other Window: </th> <td> <input type="button" onclick="OpenWindow();" value="Open Window" /><br /> <input type="button" onclick="UpdatePopPup();" value="Update PopUp" /> </td> </tr> </table> </form> </body> </html> <script type="text/javascript" language="javascript"> // Local Scripts function Count() { var objCounter = document.getElementById('showCounter') objCounter.value = ++objCounter.value; } function Write() { WriteMessage(document.getElementById('InMsg').value); } function WriteMessage(inMsg) { var objMsg = document.getElementById('OutMsg'); objMsg.innerHTML = inMsg; } </script> <script type="text/javascript" language="javascript"> // Other window scripts var newWindow = null; function OpenWindow() { newWindow = window.open('page2.aspx'); } function UpdateOpener(txtMsg, txtCounter) { document.getElementById('InMsg').value = txtMsg; document.getElementById('ShowCounter').value = txtCounter; Write(); } function UpdatePopPup() { if (newWindow != null) { Write(); var txtMsg = document.getElementById('InMsg').value; var txtCounter = document.getElementById('ShowCounter').value; newWindow.UpdatePopPup(txtMsg, txtCounter); } } </script>

Pop-up page:

<html> <head> <title>*** POP-UP ***</title> </head> <body> <form id="form1" runat="server"> <table border="1"> <tr> <th> Counter: </th> <td> <input type="button" onclick="Count();" value="Count" /><br /> <input type="text" id="ShowCounter" value="0" /> </td> </tr> <tr> <th> Message: </th> <td> <input type="button" onclick="Write();" value="Write" /> <span id="OutMsg">...</span><br /> <input type="text" id="InMsg" value="..." /> </td> </tr> <tr> <th> Other Window: </th> <td> <input type="button" onclick="CloseWindow();" value="Close Window" /><br /> <input type="button" onclick="UpdateOpener();" value="Update Opener" /> </td> </tr> </table> </form> </body> </html> <script type="text/javascript" language="javascript"> // Local Scripts function Count() { var objCounter = document.getElementById('showCounter') objCounter.value = ++objCounter.value; } function Write() { WriteMessage(document.getElementById('InMsg').value); } function WriteMessage(inMsg) { var objMsg = document.getElementById('OutMsg'); objMsg.innerHTML = inMsg; } </script> <script type="text/javascript" language="javascript"> // Other window scripts function CloseWindow() { window.top.close(); UpdateOpener(); } function UpdateOpener() { if (window.opener != null) { Write(); var txtMsg = document.getElementById('InMsg').value; var txtCounter = document.getElementById('ShowCounter').value; window.opener.UpdateOpener(txtMsg, txtCounter); } } function UpdatePopPup(txtMsg, txtCounter) { document.getElementById('InMsg').value = txtMsg; document.getElementById('ShowCounter').value = txtCounter; Write(); } </script>

 

Hope that helps...

 

This was selected as the best answer