2

What I'm trying to do is have an Apex command button that on the click opens a new VF page and also, have an action that does some backend query to get data ready for the popup VF page.

Not sure why this isn't working. Anyways, here's my code :

These next two blocks of code are located on the same VF page FYI :

<apex:outputPanel>
   <apex:inputText required="true" label="Source"/>
      <!--<input type="button" onclick="openPopup()" value="open popup"/>-->
      <apex:commandButton value="open popup" onclick="openPopup()" action="{!executeQuery}"/>
</apex:outputPanel>




 <script type="text/javascript">
    var newWindow = null;
    function openPopup() {
      newWindow = window.open('OMTCustomPage2', 'Popup', 'height=500, width=500');
    }

    function closePopup(object,name) {
      if(newWindow!=null)
         newWindow.close();
    }
 </script>

And this is in the 2nd VF page which is the popup :

 <script type="text/javascript">
    var newWindow = null;

    function openPopup() {
      newWindow = window.open('OMTCustomPage2', 'Popup', 'height=500, width=500');
    }

    function closePopup(object,name) {
      if(newWindow!=null)
          newWindow.close();
    }
</script>
1

You command button is actually running the action method in it's own onclick handler (you would normally not define an onclick handler on a command button).

Try this instead:

<apex:commandButton value="open popup" oncomplete="openPopup()" action="{!executeQuery}"/>

What this does is run your back-end query, then open the popup. You can't easily do this asynchronously.

Make sure that your return value for this controller function returns either void or a null PageReference.

1
  • Thanks! Yeah, that makes sense. I was thinking something around there too but I'm still new to VF so didn't want to make an assumption without an expert's thoughts. Thanks again! Have an awesome day! Jul 31 '16 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.