Is there any way we can add Execute Javascript custom page button to Visualforce page and reuse it. I am just checking if any way we can save writing JS code is button again in VF page.
MY Visualforce page in Question is StandardController Page.
Is there any way we can add Execute Javascript custom page button to Visualforce page and reuse it. I am just checking if any way we can save writing JS code is button again in VF page.
MY Visualforce page in Question is StandardController Page.
You should be able to store your JavaScript as JS file in a Static Resource. Then use REQUIRESCRIPT (see trick and caviets here) in the Custom Button script and INCLUDESCRIPT in the Visualforce page. This should allow you to share your JavaScript.
Alternatively, depending on your skills and use case, you could also consider writing some shared Apex code either as a shared function between two controllers or a single controller used by both the Custom Button VF page and the other VF page/s in your solution.
There's an idea: Allow references to Static Resources on Custom Buttons with OnClick JavaScript. In it there's a link to this blog post Using static resources with Salesforce custom Javascript buttons that outlines a hack that would allow you to have a single source of the JavaScript reside in a static resource and refer to it from the custom button using the REQUIRESCRIPT
function.