Insert JavaScript into a Content Editor Web Part (CEWP)

In 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!

avatar

About Adam Preston

Adam is a Senior Consultant specializing in the administration and configuration of SharePoint. He holds several SharePoint certifications, including MCITP: SharePoint Administrator 2010. He is the Vice President of the Richmond SharePoint Users Group and active throughout the SharePoint community via Twitter (@_apreston) and MSDN Forums.
This entry was posted in Development and tagged , . Bookmark the permalink.

7 Responses to Insert JavaScript into a Content Editor Web Part (CEWP)

  1. Pingback: Insert JavaScript into a Content Editor Web Part (CEWP) « SP2010 Blog

  2. Pingback: How to: Localize Custom Script Resources in SharePoint 2010 (Abhishek Verma) | MSDN Blogs

  3. Pingback: Insert JavaScript into a Content Editor Web Part (CEWP) « SharePoint Adam

  4. Pingback: Web Parts | Pearltrees

  5. avatar Gilles says:

    Thank you for sharing this tip. It worked ;)

  6. avatar Peter says:

    Professional description, thank you.
    This could be an alternative to do it with jQuery and without a Content Editor Web Part :
    http://sharepoint-design-tools-services.getyournet.ch/#product2

  7. Pingback: SharePoint 2010: How to add a new document to a document library via a link/url | Dawsonweb's Blog

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>