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
JJJenkinsJJJenkins 

javaScript window.close() not working for pop up

I have a button on a standard page layout that launches a vf page through javascript:

{!requireScript('/soap/ajax/24.0/connection.js')}
var windowRef;
var intervalId = 0;
 
setTimeout(checkToOpenWindow, 2*1000);
 
function checkToOpenWindow()
{
windowRef = window.open("https://cs7.salesforce.com/apex/AcctUpdate?id={!Account.Id}","menubar=1,resizable=1,width=800,height=250");
checkWindowStatus();
}
function checkWindowStatus()
{
intervalId = setInterval(checkAndCloseWin, 5*1000);
}
function checkAndCloseWin()
{
if(windowRef.closed)
   {
    clearInterval(intervalId);
    window.parent.location.href = window.parent.location.href;
  }
}

 Then in the VF page that launches I have a button that I would like to do a submit and save function.  I'm using the account standard controller and the standard {!save} functionality then calling some js onclick.  All of the javascript works except for window.close().

 

Here is the breakdown of the vf page and the JS:

<apex:page standardController="Account" extensions="AcctTaxonomy" sidebar="false" showHeader="false">
    
    <apex:form >
    <div id="Acct">
        //THERES A BUNCH OF VF BEFORE THIS
        <apex:commandbutton action="{!save}" value="Submit & Save" onclick="submitSelections()"/>
    </div>
    
    <script type="text/javascript">
        beenFocused = true;
               
                
       //THERE ARE OTHER JS FUNCTIONS I LEFT OUT FOR BREVITY
        function submitSelections()
           {
               serviceSelect();
               attributeSelect();
               window.close();          
           }   
    </script>
    </apex:form>
</apex:page>

 any thoughts?

sfdcfoxsfdcfox

Possibly because you're in Developer Mode? Try using window.top.close instead. Generally a window can only be closed by script when it was opened by a script, so this is most likely the cause.

ashishkrashishkr

Thanks sfdcfox. your solution worked for me.