Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can we add javascript in CEWP 2010?

share|improve this question
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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