I remember seeing somewhere that you can include an external JavaScript file in a SharePoint feature if it is in the _layouts folder. For the life of me I can't remember how to do this!
Where JSDemo/jquery-1.4.2.js is in the /_layouts/ folder. /_layouts/ is prefixed automatically |
|||
|
|
|
You can deploy a javascript file from a Feature by placing it in a Module element, so that it is copied to the layouts folder, or the Style Library or any other library in the site. Here's a tutorial on MSDN how to do it: How to provision a file. Here's another question on StackOverflow which asked something similar, but with XSL files. Just change the XSL files for your javascript files for the same effect (this is for 2007, but the resultant Elements XML file is identical). |
|||||
|
|
It depends on the scope you want. If you want your script file to be scoped to the farm, deploy it to a folder under the _layouts folder (the _layouts folder itself should be reserved for files from Microsoft). You do this using a mapped folder in Visual Studio 2010 (http://msdn.microsoft.com/en-us/library/ee231521.aspx) If you want your script file to be scoped to the site collection only, you can deploy it to the style library (as suggested by Etienne) but you need to make sure to secure it so end-users don't edit/delete it. Another option is to use a module (as suggested by James) to deploy the file to the virtual file system. |
|||
|
|
|
As James Love commented, you can only deploy to _layouts by editing the manifest.xml and hand rolling your DDF file. I've found STSDEV useful for helping me with this in MOSS 2007 but I don't know if it plays nicely with SPT 2010. |
|||||||
|
|
You can place it here if you want: http://SITENAME/Style%20Library/Forms/AllItems.aspx or If you want to have some JavaScript to run on your page simple add a Content Editor Web Part on your page and place your JavaScript in there. |
||||
|
|