Visualforce: Perform action then close window

I was looking for a quick way to have a Visualforce page perform an <apex:commandButton> action (such as save) then close the window in one fell swoop. Turns out it’s as simple as this, thanks to user andresperez:

  <apex:outputPanel id="buttons">
    <apex:commandButton action="{!save}" value="Add to List" status="closer" rerender="buttons"/>
    <apex:commandButton value="Cancel" onclick="window.close()"/>
    <apex:actionStatus startText="(Saving...)" stopText="" onStop="window.close();" id="closer"/>

Works great for a handly little popup.

This entry was tagged , , , . Bookmark the permalink.

5 Responses to Visualforce: Perform action then close window

  1. Rick Arnett says:

    The javascript call should actually be “” to get it to work properly.

  2. Rick Arnett says:

    or at least I needed to use to get it to work properly :)

  3. Julie says:

    Hiya, i couldnt get it to work with either

    Using this:

    i have this already – clicking ‘close’ does close the whole window

    the problem ive got with that is letting them know when its saved so they can close it themselves, so i thought i would use your snippet, but no cigar.

    Any tips? :):)

  4. Julie says:


    I managed to do it by changing save to quick save as i read that save will redirect you to another page after closing

    issue i got now is that it still allows save if required fields are not filled out! Help


Comments are closed.