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
sahisahi 

To open a link through new tab

 

Hi

 

                          In my application when a link is clicked through new tab it should direct to the respective

                            record,through Java Script.

 

                                                  can any one help me.

Best Answer chosen by Admin (Salesforce Developers) 
b-Forceb-Force

as salesfoce instance name get changed as per edition and Sandbox instances.

 

you can get current server url as,

 

controller side

 

public String SerUrl {get;set;}

in constructor,

SerUrl=ApexPages.currentPage().getHeaders().get('Host');

 

use this SerUrl variable in VF page instead of hardcoded  url

 

Thanks,

Bala

 

 

All Answers

b-Forceb-Force

by simply specifying target="_blank" in your href tag

 

also please explain your requirement in more details

 

Thanks,

Bala

charan@appcharan@app

Ahlada!

 

 

Use apex:outputlink or <ahref> tag and keep target="_blank"

 

 

so you can open the link in new tab.

sahisahi

 

 

 

Thanks for your Reply

 

             I have given a command link to the record and when user clicks on the link it should direct the user to the particular record, url should be generated to particular record dynamically and data should be opened in a new tab.

 

 

             I can achieve this through Command link but cannot open in new tab.

Its working fine with outputlink or <a href> tag of HTML.

 

<apex:outputlink value="https://ap1.salesforce.com/{!emp.id}">{!emp.name}</apex:outputlink>

 

or

 

<a href=https://ap1.salesforce.com/{!emp.id}" target="_blank">{!emp.name}</a><br/>

 

I gave directly the particular url id here. It differs from edition to edition.

 

Kindly suggest me how to overcome this issue.

b-Forceb-Force

as salesfoce instance name get changed as per edition and Sandbox instances.

 

you can get current server url as,

 

controller side

 

public String SerUrl {get;set;}

in constructor,

SerUrl=ApexPages.currentPage().getHeaders().get('Host');

 

use this SerUrl variable in VF page instead of hardcoded  url

 

Thanks,

Bala

 

 

This was selected as the best answer