JavaScript in Content Editor WebPart SharePoint

In this article, we will discuss how to insert JavaScript code in Content Editor WebPart in SharePoint. Also you can check out my previous posts on:

Event Receivers in SharePoint 2010

SharePoint deveopment training course

Restore a Site Collection in SharePoint 2010

CAML Query Builder in SharePoint 2013 Online

Here we will see how we can insert JavaScript into a Content Editor Web Part.

First, open a notepad and write the JavaScript code. Here I have used simple code to write Hello World as below.

<script language=”JavaScript”>
document.write(‘Hello World !!!’);
</script>

Now Save the file with a name(Here name is MyJavaScript.txt). Now we can put the text file in the Site Assets Library and also we can put the code in the layouts folder.

Copy the text file and put it inside the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\STYLES folder.

Open the page where you want to add Content Editor Web Part and edit the page. After that in the edit mode click on Add web part and from the Ribbon select the Media and Content web part category and select Content Editor web part and then click on Add.

Now go to the Content Editor web part properties. From the properties select Content Link and give path of the text file that contains the JavaScript code. Since we have saved the file in the layouts folder the path will look like:
http://[Server Name]/_layouts/Styles/MyJavaScript.txt .
Click on OK.

Then Save and Close the page, now our JavaScript code will appear.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →