+ Start a Discussion
renuamirenuami 

automatically close VF Page after performing Save action

My requirement is to automatically close VF Page after clicking the save command button.

 

 

<script>
function closeRefresh()
{
top.parent.window.opener.location.href = "/003/o";
top.parent.window.close();
}
</script>

<apex:commandButton value="save" action="{!save1}" onclick="javascript&colon;closeRefresh();"/>

 

 

 

I am clicking on the link on the List view section of the consoleconsole. VF Pages open which have a save button. Which when clicked updates some values on the contact Object and should close this opened VF Page.

 

I am trying this with as shown above but not able to get it to work. Please advise!!!Thanks..

 

 

Message Edited by renuami on 08-19-2009 01:18 PM
grassrootsgrassroots

 

Are you talking about a save and redirect in VF? 

 

 

<apex:commandButton action="/apex/YourPageHere?id={!ID}" value="Save and Complete"/>

 

 

 

sfdcfoxsfdcfox

You can use the onComplete attribute of an action tag to perform a JavaScript action. Of course, you can't close a window you didn't open (or at least, the user will receive a prompt). For example:

 

<apex:page controller="myController"> <script> function closeWindow() { window.close(); } </script> <apex:form> <apex:inputText value="{!myValue}" /> <apex:commandButton value="Submit" action="{!save}" oncomplete="closeWindow()" /> </apex:form> </apex:page>

 For additional information, I would recommend the Visualforce Developer's Guide.

 
renuamirenuami

Thanks for the Response.

 

I did try this. When i click on save it saves the contact record. But the window is not closing.

 

I am opening this VF Page by clicking on the link in the console. Is anything different when doing from console.

 

I really have a very immediate requirement which needs to be done ASAP....if anyone can throw some idea that would be much appriciated...

 

In the Listview section of the console, one of the field is formula field.

 

 

HYPERLINK("/apex/myVFPagename?id=" & Id, IMAGE("/servlet/servlet.FileDownload?file=01540000000GTDE", "Hello"))

 

When i click on Hello myVFPagename will open which has a Save button. When clicked on that it has to save some values in the contact and should close that open page/window.

 

I

 

bob_buzzardbob_buzzard

Your popup window cannot close itself, as it didn't open itself.  I hit exactly this problem with a custom lookup page.  The close method needs to be executed from the window that created the popup.

 

You will need to move your close javascript method to the page that creates the window, and invoke that from the popup page.

 

 

bob_buzzardbob_buzzard

Here is the code from my popup window:

 

 

function CloseWindow() { var winMain=window.opener; if (null==winMain) { winMain=window.parent.opener; } winMain.closePopup(); }

 

 

 

The closePopup function exists in the page that opens the popup.  Thus the popup window has to ask its opener to close it, if that makes sense.

renuamirenuami
Its makes sense. But in my case since i am opening the window from the formula field is there any way to call the closeWindow() function from there?
Atul Thakur 16Atul Thakur 16

Hi Renuami,

In ditto situation, Did you get any workaround ?

Thanks,
Atul

Manohar SF.ax1874Manohar SF.ax1874
another solution that worked for me - https://salesforce.stackexchange.com/questions/63421/close-window-oncomplete-not-working
Brad Nordling 9Brad Nordling 9
I have similar issue but popup is being opened from a record page of the parent.  How can I create a function within the record page to call to "ask its opener to close it"?