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
Kim AdilKim Adil 

Remove absolute URL and replace with relative URL in Javascript button

I have a button that route users to seperate URL links based on a checkbox selection. I would like to remove the hard coded URL and use relative instead. Thanks
 
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}


if ({!CustomObject__c.checkbox__c}== false)
{
var URL1 = "https://c.cs11.visual.force.com/apex/ObjectCustom?id=" + '{!CustomObject_A__c.Id}';
window.open(URL1);

}
else
{
var URL2 = "https://c.cs11.visual.force.com/apex/ObjectCustom?id=" + '{!CustomObject_B__c.Id}';
window.open(URL2);
}

 
Best Answer chosen by Kim Adil
@Karanraj@Karanraj
Kim,

It's not required to enter completed URL in the javascript button code, just add the from /apex/visual force page name. Try with the below to work dynamically in different environments
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}


if ({!CustomObject__c.checkbox__c}== false)
{
var URL1 = "/apex/ObjectCustom?id=" + '{!CustomObject_A__c.Id}';
window.open(URL1);

}
else
{
var URL2 = "/apex/ObjectCustom?id=" + '{!CustomObject_B__c.Id}';
window.open(URL2);
}