How to enable script editor webpart in SharePoint online

In 2 Steps Enable Script Editor Webpart in SharePoint online

No comments

Loading

Enable script editor webpart in SharePoint online – in this article, we will learn In just 2 commended steps Instantly enable script editor web part in SharePoint online. a few days back one of my colleagues reported to me that he is not finding the script editor web part on SharePoint online site. After some analysis, we learned that on SharePoint online site script editor web part is not available by default. In order to make it available, we need to enable the custom script from the SharePoint Tenant admin center. Here, in this article, I will explain how to enable this.

What is Script Editor Webpart in SharePoint Online?

The Script Editor Web Part in SharePoint Online is a tool that allows users to add custom HTML, CSS, and JavaScript directly onto a SharePoint page. This web part is useful for adding advanced functionality or customized content that is not available out-of-the-box in SharePoint.

Key Features and Uses:

  1. Customization: You can add custom scripts to enhance the user interface and functionality of SharePoint pages.
  2. Flexibility: It allows for the insertion of external content such as iframes, scripts from third-party libraries, and custom code snippets.
  3. Integration: You can integrate with other systems or services by embedding their scripts directly on the page.
  4. Styling: Use CSS to style elements in a way that matches your organization’s branding or specific requirements.

How to Use the Script Editor Web Part:

  1. Add the Web Part to a Page:
    • Navigate to the SharePoint page where you want to add the web part.
    • Edit the page by clicking the “Edit” button.
    • Click the “+” button to add a new web part.
    • Select the “Script Editor” web part from the list of available web parts.
  2. Insert Your Code:
    • Once the web part is added, click on the “Edit Snippet” button.
    • A dialog box will appear where you can insert your HTML, CSS, and JavaScript code.
    • Click “Insert” to save your code.
  3. Save and Publish:
    • After inserting your code, save the page and then publish it to make the changes live.

Considerations:

  • Security: Be cautious about the code you insert, as it can potentially introduce security risks such as cross-site scripting (XSS) vulnerabilities.
  • Performance: Heavy or inefficient scripts can impact the performance of the SharePoint page.
  • Maintenance: Custom scripts require proper documentation and maintenance, especially during SharePoint updates.

Limitations:

  • Modern Pages: The Script Editor Web Part is not available in the modern SharePoint experience. For modern pages, Microsoft recommends using the SharePoint Framework (SPFx) to implement customizations.

Alternatives:

  • Content Editor Web Part: Similar to the Script Editor, but generally used for embedding HTML content.
  • SharePoint Framework (SPFx): For modern sites, SPFx offers a more robust and supported way to add custom functionality and integrations.

The Script Editor Web Part provides a powerful way to extend the capabilities of SharePoint Online with custom scripts and styles, making it a valuable tool for developers and advanced users looking to tailor SharePoint to their specific needs.

Verify that the script editor web part is not available by default: Script Editor web part not showing SharePoint Online

Navigate to the edit your web part page – > Insert -> Web Part -> Categories ->Media and Content

Here we can see that the “Script Editor” web part is missing. Not only that we can not see also the “Content Editor” web part and many more. Please see the below screenshot:

Script editor web part is missing under Media and Content in SharePoint Online
The script editor web part is missing under Media and Content in SharePoint Online

Now go to your tenant setting page thru this URL

sprnd-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx

Note: Here “sprnd” is my tenant name, you need to pass your tenant name.

Now see the “Custom Script” section by default both the radio button is selected as prevent – this is the default behavior and due to this script editor and content editor web part is missing from SharePoint online page.

  1. Prevent users from running custom script on personal sites.
  2. Prevent users from running custom script on self-service created sites)
Prevent users from running custom script on personal sites in SharePoint Online
Prevent users from running custom script on personal sites in SharePoint Online

 

Now select to allow users to run the custom script for both the radio button as below:

  1. Allow users from running custom script on personal sites.
  2. Allow users from running custom script on self-service created sites)
Allow users from running custom script on personal sites in SharePoint Online
Allow users from running custom script on personal sites in SharePoint Online

 

Now click on ok and once you save it, this may take 24 hours to reflect the changes – this is what the message says from Microsoft but this was not correct at least for us. We had waited for around 3 days but still didn’t see the script editor web part on my page.

Then what to do?

Enable the custom scripting using the PowerShell script

To overcome this issue run the below PowerShell script – this will immediately add the script editor and content editor web part in the web part category.  This is the reason to write and share this article.

$adminUserID="youradminaccount@< sprnd.onmicrosoft.com>"

$userCredential = Get-Credential -UserName $adminUserID -Message “Enter password”

Connect-SPOService -Url sprnd-admin.sharepoint.com/ -Credential $userCredential

Set-SPOsite "sprnd.sharepoint.com/sites/TestSite001" -DenyAddAndCustomizePages 0

Notes:

  1. It should be your tenant domain account and your actual site.
  2. Here I have used my test trial tenant site.
  3. In Connect-SPOService pass your tenant admin URL
  4. In Set-SPOsite pass the site URL where you want to add the script editor web part.
  5. If your tenant admin account has MFA (multi-factor authentication) enabled, you cannot execute this – to execute this script use the account which does not have MFA enabled.

Verify that the script editor web part is available after executing the PowerShell Script: Enable script editor web part in SharePoint online

After executing the above script – immediately come to the same page – wow we can see the script editor, content editor, and many other web parts that were not there before the script execution under “Categories”:

Script editor web part is available in SharePoint Online
Script editor web part is available in SharePoint Online

Why does Microsoft not allow to add the script editor web part by default (script editor web part in SharePoint online)?

Considering the utmost security – Microsoft does not recommend adding the custom script to the page. If we want to add any custom scripting to our SharePoint online page – we need to add these out thru the SPFx framework.

Summary: Enable script editor web part in SharePoint online

Thus, in this article, we have learned about how to enable the script editor web part in SharePoint online.

See Also: SharePoint Online Tutorial

You may also like the below SharePoint Online tutorials:

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment