How can we help you today?

How to Add JavaScript Code to a Page Using the Script Editor Web Part (SharePoint 2013/2016)

You have an HTML, JavaScript or CSS snippet that you want to inject into the page, without having it cleared out by the SharePoint editor? This article will show you how to do it using the Script Editor Web Part.



TABLE OF CONTENTS


Before we begin


Please note: This method is only applicable to Classic pages in SharePoint 2013 and SharePoint 2016 environments. If you are using SharePoint 2019 or Office 365, please use the Code Design Element instead.


Step 1: Add the Script Editor Web Part


From ribbon bar, click Web Part (you can add it anywhere on the page, it does not matter, as it will not render anything):


Click Web Part


Under Categories, choose Media and Content > Script Editor and click Add:


Add Script Editor



Step 2: Edit the Web Part


Activate the Web Part by clicking it, then a new tab Web Part in the ribbon will appear:


Activate Web Part


Then next, click the Web Part Properties button:


Click Web Part Properties


Step 3: Add the Code into the Web Part


The page will refresh, and the Script Editor Web Part will appear now in edit mode, click on Edit Snippet, to bring up the dialog that will allow you to paste some JavaScript code into the page.


Click Edit Snippet


Now you can paste whatever HTML code you have into the Embed dialog:


Embed window



Please note, that script tags are required when adding custom JavaScript to your Sharepoint Site:



Paste script



Related articles:

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

World's best intranet sites are designed using ShortPoint

Get started today! Learn more
See all 25 topics

Start a trial

Ignite your vision. Install ShortPoint directly on your site, or play in sandbox mode. No credit card required.

Get started today

World’s best intranet sites are designed using ShortPoint

Thousands of companies using ShortPoint everyday to design, brand and build award winning intranet sites.

Get started Learn more