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
Francesco SciutoFrancesco Sciuto 

How to retrieve Site.BaseURL from JavaScript

I have an object layout displayed as a tab inside Sales Console. I have some Javascript attached to the onClick event of a button on the layout. In the Javascript I would like to retrieve the Base URL displayed in the browser. So if I have 'https://[instancenumber].salesforce.com/console' I would like to get 'https://[instancenumber].salesforce.com'. I use within Javascript:

console.log({!$Site.BaseUrl});

but I always get NaN. I know that I might use Javascript directly but I would like to know why this Salesforce approach does not work and I can make it work. Thanks
Renato SoluRenato Solu
The correct use is:
console.log('{!$Site.BaseUrl}');
because the tag gets replaced by the actual content, and strings in JS need to be wrapped with simple quotes.
Srini GrandhiSrini Grandhi
It did not work for me.