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
Shane K 8Shane K 8 

Visualforce link right click to open in a new tab

Hello,

I have a visualforce page that has link to a record id, when left click the link the record opens fine. When I right on that link and choose "Open link in a new tab" a new tab opens but the the URL is "about:blank#blocked".  How can I display the record page in the new tab?

Thanks.
AbhishekAbhishek (Salesforce Developers) 
When we make use of the apex command link then it sends the request to the server and here the server redirects the page. But when we make use of open in new tab then sever loses the page reference for it that’s why it opens up the parent page.

Here you can make use of output Link that works as anchor tag (  i.e <a href="#">click</a>). This works fine for the above requirement.

Try the below code snippet as a reference.

<apex:page controller="cmdlinkDemo" >

<apex:form >

  <apex:commandLink action="{!gogoogle}" target="_blank" value="Go Google"  id="theCommandLink"/><br/>

  <apex:outputLink value="https://www.google.co.in/" id="theLink">Go Google2</apex:outputLink>

</apex:form>

</apex:page>

 

=====Apex Controller========

 

public class cmdlinkDemo

{

 

    public PageReference gogoogle()

 {

       PageReference pageRef = new PageReference('https://www.google.co.in/');

       pageRef.setRedirect(true);

       return pageRef;

    }

 




Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.
Shane K 8Shane K 8
Hi Abhishek,

Thanks for the example. I have the following code in my VF page. I am not sure how to fit the new tab functionality with reference to your example. Can you please help me?
 
<apex:outputPanel layout="block">
 <apex:outputText >Opportunity Name:</apex:outputText>
   <apex:outputLink value="/{!Opp.Id}" >
      <apex:outputText>{!Opp.Name}</apex:outputText>
   </apex:outputLink>
</apex:outputPanel>

Thanks.