SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can we add javascript in CEWP 2010?

share|improve this question

CEWP strips some scripts, check this workaround that explains how you can still reference a script from an external file, it's not the best practice so you should (if possible) deploy JavaScripts via SharePoint feature.

share|improve this answer

Deploy your .js file to SiteAssets folder of your site with Sharepoint Desighner. You may apply the file in your CEWP html.

​​<script src="/SiteAssets/Scripts/name.js" type="text/javascript"></script>

Take into account the time when SP.js is already loaded.

<script type="text/javascript">
  ExecuteOrDelayUntilScriptLoaded(getListItems, “/_LAYOUTS/sp.js”);
</script>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.