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
leloupleloup 

Can not close Pop-up VF page

Hello

 

I have popup vf page which is opened by custom button. It uses standard controller with extension. And the problem is that it uses standard save() method and it never closes. I tried to apply solution from here

http://boards.developerforce.com/t5/Visualforce-Development/Closing-Popup/m-p/187900/highlight/true

but it doesn't work. The javascript function is loaded and passes if-condition but the window is not closed. Here is my code, maybe someone have an idea what's the problem is:

<apex:page standardController="Opportunity" extensions="PPOppWonController"
sidebar="false" showHeader="false" standardStylesheets="false" wizard="false" id="pg"  >
  <html>
   <head></head>
<body onload="checkStatus();"></body>
</html>
    <apex:form id="frm" >

        <table>
            <tr>
                <td valign="top">
       
                   <apex:inputTextarea id="sReasonWon" value="{!sReasonWon}" cols="35" rows="5"
                        onkeypress="return disableEnterKey(event)"></apex:inputTextarea>
                        <apex:inputHidden id="stat" value="{!sStatus}" />
                        </td></tr>
                       <tr> <td>
                    <apex:commandButton action="{!save}" id="btn" value="Request Won " />

                </td>

            </tr>
        </table>
        <script>
            var btn = document.getElementById("{!$Component.btn}");  

            var sts = document.getElementById("{!$Component.frm.stat}");
     </script>
    </apex:form>
    <script type="text/javascript">
               
        function disableEnterKey(e)
        {
        var key;
        if(window.event)
        key = window.event.keyCode; //IE
        else
        key = e.which; //firefox
        return (key != 13);
        }       
         function checkStatus(){
                        
                 if(sts.value == 'saved'){
                   
                        self.close();
                  } }
        
      </script>

</apex:page>

Thank you in advance! Any help is welcome

Best Answer chosen by Admin (Salesforce Developers) 
leloupleloup

I solved it by using  window.top.close(); instead of self.close();

All Answers

leloupleloup

I solved it by using  window.top.close(); instead of self.close();

This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

You can also use window.parent.close() or window.close().