Tuesday, July 10, 2012

Insert JavaScript into a Content Editor Web Part (CEWP)


n the 2007 version of SharePoint, we had the Source Editor included in the Content Editor Web Part (CEWP) as our way of inputting JavaScript directly onto a page. The process on how to do this has changed a little bit in the new 2010 version. Follow below on how to successfully perform the same task.
Instead of having a Source Editor to directly paste in our code, we need to first create a simple text file and save our code there. Once saved, upload that file to SharePoint. I am using the Site Assets library for this demo and a JavaScript that displays today’s date. After you have uploaded the file, right click on the file and select Copy Shortcut.
Now, go to your desired page and put the page in edit mode. Add in the Content Editor Web Part located under the Media and Content category. Once added select the web part and use the ribbon UI to navigate to the Web Part Properties screen.
On the web part properties screen, paste in the URL link to your uploaded JavaScript file. Click OK on the properties screen and, if your JavaScript is valid, it should display the desired results! Simple and easy!
    

No comments:

Post a Comment