+ Start a Discussion
csbaacsbaa 

redirect to a new Vf page on another separate TAB

Hello Helpers

 

 

I have a VF page  with a command  button (among others)

 

<apex:commandButton action="{!MycontrolerFunction}"  value="{!someValue}"/>

 

when the MyControllerFuntion is finished I want to redirect  to a new page

 

For this I am using:

 

PageReference pageRef = new PageReference('/apex/MySecondPage');
pageRef.setRedirect(true);
return pageRef;

 

 

This open the new VF page  on the same  tab overwriting the initial page

 

What I want to achieve  is to  open the new VF page on a new  tab

 

 

Is it possible

 

Thanks in advance 

csbaa

Best Answer chosen by Admin (Salesforce Developers) 
digamber.prasaddigamber.prasad

Hi, 

 

You can use onComplete attribute of CommandButton. Updated CommandButton may look like:-

 

<apex:commandButton action="{!MycontrolerFunction}"  value="{!someValue}" oncomplete="window.open('<URL of 2nd page>')"/>

 

One more catch is your controller should return null from action method. Something like below:-

 

public pagereference someValue(){

  // your code

  return null;

}

 

Let me know if you have any specific question about above.

 

Happy to help you!

 

Regards,

Digamber Prasad

 

 

All Answers

Starz26Starz26

Then use javascript in you VF page window.open(...params....) instead.

 

 

digamber.prasaddigamber.prasad

Hi, 

 

You can use onComplete attribute of CommandButton. Updated CommandButton may look like:-

 

<apex:commandButton action="{!MycontrolerFunction}"  value="{!someValue}" oncomplete="window.open('<URL of 2nd page>')"/>

 

One more catch is your controller should return null from action method. Something like below:-

 

public pagereference someValue(){

  // your code

  return null;

}

 

Let me know if you have any specific question about above.

 

Happy to help you!

 

Regards,

Digamber Prasad

 

 

This was selected as the best answer
csbaacsbaa

Hello 

 

I tried but I still have  problems

 

my second  VF page  needs  a parameter  which depends on a selection  from  a checkbox  in the first page

I wrote a event handler method for the oncomplete  where I calculated the url

 

the URL is calculated properly.  If  I use an alert(url);   in my  javascript  program  the right dynamic url is displayed

but  if I use window.open(URLu);   nothig happen

 

 

actualy   it seems to me that I can not open the window  from inside the javascript  function

the simple  function below does not work

 

<apex:commandButton oncomplete="viewHierarchy()" value="View Hierarchy 1"/>  

 

function viewHierarchy()
{


window.open('www.google.com');
return;

}

 

 

my function looks as below:

 

function viewHierarchy()
{

var idu;  //id of the selected acount and later parameter of the VF page
var elems = document.getElementsByTagName('input') ;
for (var i=0;i<elems.length;i++)
{
var e = elems[i];
if ( e.type=='checkbox' && e.checked)
    {
     // Copy the ID of selected Account to parent window, and then pop this down
     var idu = document.getElementById(e.id.replace('cbox','acctId')).innerHTML ;
     break ;
     }
}

 

var URLu = '/apex/VEEVA_HIERARCHY_BUILDER?pid=' + idu;

if(idu != '')
   {
   //alert(URLu);                         IF I uncomment  this I see the good URL 
   window.open(URLu);           NOTHING HAPEN  HERE
   }
else
alert('No account selected!);
}

 

 

csbaacsbaa

I found the error in my  code so disregard my previous message

 

Thanks  for your support 

 

ocomplete()  is a good event

 

 

Regards

Csbaa

digamber.prasaddigamber.prasad

Happy that you my reply helped you in finding solution. Could you please give me a KUDOS, if it helped you!

 

Happy to help you!