Inject javascript into a page from a feature
-
16-10-2019 - |
Question
I want to add a verb (link in the top left menu of a web part) to all the web parts in Sharepoint 2010. Is there a way to inject javascript into a all the pages from a custom feature?
Solution
You can write a custom control that uses the SharePoint scriptlink control and furthers registers your JS file using the ScriptLink.Register method on the page.
Next you can deploy this custom control as a delegate control. You can use any existing delegate control like AdditionalPageHead inside the master page or create a new one.
OTHER TIPS
somehow injecting javascript into all the pages just sounds like a bad idea, you could however alter the master page to include a javascript file and deploy the updated master page as part of the feature.
Do you really need to add your action as a webpart verb?
Is Ribbon UI or a Site Action acceptable?
How to: Modify the User Interface Using Custom Actions
This series of articles goes into more depth.