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
Sravan PSravan P 

How to open a VF page as a pop up in another VF page's onclick?

Hi I have a command link on a Visualforce page and I need to open another VF page as a popup window on click of the commnad link.

This is my Commnad link in the main VF page.

<apex:CommandLink Value="Select Product" onclick="window.open('/apex/oppprdpage?id={!as.lnkass.SalesOpportunityId__c}')"/>

Right now, on click of this link the new page is opening as a new tab but I need to open the new VF page as a popup window. Is there any way that I can achieve this?  (Basically I am trying to replicate the standard lookup window).


Thank You in advance for your help!!

 

Regards,

Sravan.

Best Answer chosen by Sravan P
OyeCodeOyeCode
That should work, worked for me - attached screenshot popUser-added image

All Answers

OyeCodeOyeCode
<apex:page >
<script language="javascript" type="text/javascript">

function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if (window.focus) {newwindow.focus()}
    return false;
}


</script>
<apex:form >
<apex:CommandLink Value="Select Product" onclick="window.open('/apex/oppprdpage?id={!as.lnkass.SalesOpportunityId__c}')"/>

</apex:form></apex:page>
OyeCodeOyeCode
That should work, worked for me - attached screenshot popUser-added image
This was selected as the best answer
Sravan PSravan P
Hi Harshit,

That worked!! Thank You for the help.

Regards,
Sravan.
Swapnil Patne 20Swapnil Patne 20
Hi guys,

I am in similar situation and need some help..

I have a command button on a Visualforce page and upon click I need to open a URL in an iFrame i.e. a web browser inside an iFrame 

Here is my code I am working.. please can you help with the correct code..?

<apex:page sidebar="False">

<apex:form >
  <apex:commandButton onclick="toGoogle();" value="Google"/>
 </apex:form>
 
  <script>
   function toGoogle() {

        redirectTo('http://www.google.com');
    }

   
    function redirectTo(target) {

        if (inIframe()) {
           // step out of an iframe (if opened via iframe)
            window.top.location.href = target;
            return false;
        } else {
          window.location.href = target;
        }
    }

    function inIframe() {
        try {
            return window.self !== window.top;
        } catch (e) {
            return true;
        }
    }
  </script> -->

</apex:page>