I am trying to add javascript to the standard layout in order to hide a button based on a condition. I have created a VF page with the java script and added that page to a section in the standard layout. However, the script doesn't work because it doesn't seem to have access to any of the UI elements. I initially suspected that the script may be loaded before the DOM but that doesn't seem to be the case. I tried to run the same script via the browser console and it seems to work fine. I am not able to figure out why the UI elements are not accessible to the script. Any thoughts and ideas are welcome .

Thanks, neel

3 Answers 3



I believe VF Pages loaded into the standard-page layouts are loaded in an iFrame. Someone can probably confirm this for me, but your going to have to have your JS access the parent of the iFrame and manipulate it.

It's been a long time since I've done this and honestly not sure if it's still possible given the security vulnerabilities.

  • 1
    I can confirm that Salesforce loads all VF pages in iframes now when the page is used on the *.salesforce.com domain. Additionally, they are loaded from the Visualforce domain which will prevent you from accessing the top-level domain from the iframe due to cross-origin request security.
    – dsharrison
    Nov 20, 2015 at 17:22

Salesforce loads all Visualforce included in detail layouts and the sidebar using iframes. The content of the iframe (your page) is loaded from c.*.visual.force.com and the top-level page is *.salesforce.com (or your custom domain). This means that you cannot access the top level page from your iframe due to cross-origin request security. Your only option for hiding buttons will be to override the detail page with a Visualforce page.


There is a hack that you can use. But, I warn you, it's ugly.

Create a sidebar component (the little boxes that appear on the left of the screen). Insert you Javascript there. Voila.

Be warned, this will not work on the lightning experience at all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .