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
TristanTristan 

Using JavaScript in a Static Resource from an OnClick Custom Link

I'm looking to replace a custom link that pops up an SControl with a new one of the "OnClick JavaScript" variety.  I've put the bulk of the code into functions in a JavaScript Static Resource file, and was hoping to reference that from the OnClick link with a {!REQUIRESCRIPT("{!URLFOR($Resource.MyJSLib)}")} or similar, but I can't get that to work.

 

{!REQUIRESCRIPT("/resource/magic-id/MyJSLib")} does work, but is obviously not really production quality or packagable.

 

Anybody have ideas how this should be done?

 

 

shillyershillyer

URLFOR returns a relative URL for a static resource archive in a Visualforce page. You could have your custom link reference a Visualforce page that calls your static resource.

 

Hope that helps,

Sati

TristanTristan

I have indeed turned JavaScript code into a Apex custom controller behind a Visualforce page in my managed package (thanks!), but not quite as SF intended.

 

I'm still using On Click Javascript still to call window.open("\apex\MyNamespace__MyApexPage?opt1=stuff&opt2=otherstuff", ...).  This is because I need to pass in arguments whereas the custom-link option for directly using Visualforce pages does not allow this, plus only having a single page rather than having one per SObject is nice.

 

So far it works, hopefully that will continue!