+ Start a Discussion
RovitaRovita 

visualforce page popup on button click

On my visualforce page, i have a button, on click of this button i want to open another VFP as a pop up window.

Tried several ways without success. Any suggestions??? Thanks


<apex:commandButton value="Send" id="email" action="{!navigateToEmail}" onclick="OpenVfpage(myrecord.id);return false"/>

<script>
   
  function OpenVfpage(pid){
       var newwindow = window.open('/apex/MYVFP?id='+myrecord.id, 'open page','_blank','scrollbars=yes,toolbar=no,status=no);
       newwindow.focus();
    }
</script>


**********************COntroller _*****************
public PageReference navigateToEmail(){
    
        PageReference page = new Pagereference('/apex/MYVFP?Id='+myrecord.Id);
        page.setRedirect(true);
        return page;
        }




VikashVikash (Salesforce Developers) 
Hi Rov,

Please try to use _blank to open a page in a new tab,you can use function OpenInNewTab(url )

{
  var win=window.open(url, '_blank');
  win.focus();
}

Please refer thi link http://www.w3schools.com/jsref/met_win_open.asp

Hope this helps.

Thanks
Vikash_SFDC
PrasanntaPrasannta (Salesforce Developers) 
Hi,

Try using this-

<script>
      function OpenVfpage(pid){
       var newwindow = window.open('{!navigateToEmail}');
    }
   <script>

And remove 'action="{!navigateToEmail}" from the <apex:commandButton> tag.

Hope it helps.


Vinit_KumarVinit_Kumar
Try below  code :-

<pre>

VF page 
<apex:commandButton value="Send" id="email" onclick="OpenVfpage"('{!str}');return false"/>

<script>
  
  function OpenVfpage(pid){
       var newwindow = window.showModalDialog("/apex/MYVFP?id="+pid, 'open page','_blank','scrollbars=yes,toolbar=no,status=no);
       newwindow.focus();
    }
</script>

You don't need your method navigateToEmail() in your controller.Just fetch the record id in your constructor and store it in a variable then you are good to go :)

something like below 

public string str{get;set;}

public constructor()
{
           str= ApexPages.currentpage().getParameters().get('recordid');//I have used this str in your onclick method above in VF page.
}


</pre>
RovitaRovita
Thanks to you all @ Vikash, @Prasannta, @vinit_kumar for your suggestions.


This is my final solution which does what i needed.

<pre>

<script>
function OpenVfpage(){
  window.showModalDialog("/apex/MYVFP?id={!recId}","dialogWidth:800px; dialogHeight:200px; center:yes");     
}
</script>


<apex:commandButton value="Send Email" id="email" onclick="OpenVfpage();"/>


Note: I am getting and setting the recId and fetching in the constructor as @vinit_kumar suggested

string recId {get;set;}

// recId = ApexPages.currentPage().getParameters().get('Id');



</pre>
Vinit_KumarVinit_Kumar
Please mark the answer as best answer to benefit others :)
samasama

hi,
i have onclcik javascript button in acount object.now i want add that Custom button in vf page.
can anyone help me on this pls.

thanks
sundarayya edasundarayya eda
Hi,
To display another visualforce page as a popup fallow bellow steps if it is a related button
EX: opportunity is parent and contract is a child
1. create a button in contract buttons and links, select link button behaviour is exicute javascript and 
Content Source is on clickjava script
write link like this window.open('/apex/PageName?Param1='+'{! Opportunity.Id }','mywindow','width=600,height=200');
2. 
write a vf page Pagename.
Add that button to the opportunity related list contracts
1.edit the opportunity layout and go to related list contract
2.press rench and in buttons section move the button to selected buttons section. save and open any opportunity record
go to contract related section you will find the button which you added. press it