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
TheCustomCloudTheCustomCloud 

jQuery on a standard layout button

Has anyone been able to get jQuery to work in a custom button for a standard page layout?  All the examples I can find are on custom VF pages :(

 

Example code or a link to example code would be very much appreciated.

 

Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
ca_peterson_oldca_peterson_old

You have to use the REQUIRESCRIPT function and link to an external resource (there's no URLFOR function available in javascript buttons sadly). There are some mirrors of jquery on google's CDN, which I'd reccomend looking up and using.

 

Like this:

{!REQUIRESCRIPT("http://example.org/jquery.js")}

$().stuff();

All Answers

ca_peterson_oldca_peterson_old

You have to use the REQUIRESCRIPT function and link to an external resource (there's no URLFOR function available in javascript buttons sadly). There are some mirrors of jquery on google's CDN, which I'd reccomend looking up and using.

 

Like this:

{!REQUIRESCRIPT("http://example.org/jquery.js")}

$().stuff();

This was selected as the best answer
TheCustomCloudTheCustomCloud

Thanks Ca_Peterson.  I am wary of using a library that is controlled by an outside source but I believe you are right that this is the only way currently.  Or I could host it external to SFDC on one of the client's hosts but that is messy too.

elyb527elyb527

You can crate a Static Resource in SFDC named jquery_1 or something like that.  And instead of using the external link, you can use this:

 

{!REQUIRESCRIPT('/resource/jquery_1)}

ca_peterson_oldca_peterson_old

That's awesome, I had no idea they provided URLs without the version string in them. Obviously cache could be an issue here, but as long as your static resource updates aren't time senstivie (they're static after all...) that path should work.

 

You rock!