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
@Suresh.ax1214@Suresh.ax1214 

How to redirect a link to new tab using pagereference in apex.

 i must use the action and rerender properties in command link.

this is my code:

 

Apex Page:

 

<apex:page sidebar="false" standardStylesheets="false" controller="LinkController">

<apex:outputPanel styleClass="app-icon" layout="block" id="app">
   <apex:form >
    <apex:commandLink action="{!Save}" reRender="app" value="rediff">
    
</apex:commandLink>
    </apex:form>
</apex:outputPanel>

</apex:page>

 

public class LinkController {

   public PageReference Save()

    {

String newPageUrl = 'http://www.rediff.com/';

   PageReference newPage = new PageReference(newPageUrl);

   newPage.setRedirect(true);

   return newPage;

    }
}

 

Thanx in advance

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code:

/////////////////////// VF Pages ////////////////////////////////

<apex:page sidebar="false" standardStylesheets="false" controller="LinkController">

 

<apex:outputPanel styleClass="app-icon" layout="block" id="app">

   <apex:form >

    <apex:commandLink action="{!Save}" reRender="app"  value="rediff" onclick="WindowNew()">

    <script>

        function WindowNew()

        {

        alert('abc');

        window.open('http://www.rediff.com/');

        }

    </script>

</apex:commandLink>

    </apex:form>

</apex:outputPanel>

 

</apex:page>

/////////////// Controller /////////////////////////

public class LinkController {

 

   public PageReference Save()

 

    {

 

String newPageUrl = 'http://www.rediff.com/';

 

   return null;

 

    }

}

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

@Suresh.ax1214@Suresh.ax1214

its working.... but without using the onClick() or any other function. the action will be performed through the pagereference method.

 

when we call the Save() method in action then it automatically open a link in new page. commandlink must have the reRender property

 

also...

 

Thanks in advance......