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
OpsterOpster 

Run custom javascript across all salesforce pages?

I am wondering if and how I can run some custom javascript across all my salesforce pages?   I tried adding my javascript to a Custom Component on the home bar, but when I try and save the component it deletes all my javascript out.  

 

I dont't want to add the javascript to each object with a layout.   I simply want this javascript to be executed onload of every page across my org.

 

Any help is greatly appreciated, and thank you in advance.

 

OpsterOpster
Did you ever find a solution for this?
Alok_NagarroAlok_Nagarro

Hi,

 

You can use a visualforce for that purpose, The trick is create a visualforce page without any controller, placed your javascript in this page within <script></script> tag. Now create a custom home page component with type of "HTML Area" an in this component write the following code -

 

<iframe src="/apex/yourPageName" height="60" scrolling="no" width="180"></iframe>

 

Adjust width & height acoordingly and save this component, now go to home page layout--> add this component to layout.

 

Hope it shud help u !

OpsterOpster

But when the side bar is closed this code is no longer run.  So your solution will also only work on pages that have the side bar enabled.

Alok_NagarroAlok_Nagarro

Exactly, This thing is totally dependent on side bar. I dont think there is another way to do the same.

Power User 14Power User 14
Note that even if you get the JavaScript to run on each page, you can't interact with the mail salesforce page since your JS will be running within an iframe on a separate domain.