SharePoint Document Issues

Fix SharePoint Online Iframe Cannot Import External JavaScript File

Bushra ParveenBushra Parveen Nov 4, 2026 868 views

Question details

The user is unable to load or execute an external JavaScript file within a custom HTML iframe in SharePoint Online.

How to Fix SharePoint Online Iframe Not Importing External JavaScript
Product
Microsoft SharePoint Online
Device & OS
not provided
Scenario
Loading custom HTML through a SharePoint iframe or Embed Code web part that requires an external JavaScript file to function.
Observed behavior
The external JavaScript file fails to import and run, preventing the custom HTML assets from rendering or functioning correctly within the iframe.
Before you start

Ensure you have Site Administrator privileges in SharePoint Online, as you may need to check or modify site security configurations and HTML field settings.

Solution 1Recommended

Enable Custom Script Settings in SharePoint

SharePoint Online blocks custom scripts by default to maintain security, which can prevent external JavaScript from executing inside iframes or web parts.

By default, SharePoint Online restricts the execution of custom scripts on self-service created sites. To allow your external JavaScript to run, an administrator must enable custom scripts at the tenant level.

1
Access the Admin Center

Log in to Microsoft 365 and open the SharePoint Admin Center using an administrator account.

2
Navigate to Settings

Click on 'Settings' in the left-hand navigation menu, then select 'classic settings page' at the bottom.

3
Modify Custom Script Options

Scroll down to the 'Custom Script' section and select 'Allow users to run custom script on personal sites' and 'Allow users to run custom script on self-service created sites'.

4
Save Changes

Click 'OK' to save. Note that it may take up to 24 hours for this change to take effect across your SharePoint tenant.

Enable Custom Script Settings in SharePoint
Security Consideration: Enabling custom scripts exposes your site to potential vulnerabilities. Only allow scripts from highly trusted sources.
Free Microsoft Office alternative

Simplify Document Management with WPS Office

Dealing with complex SharePoint scripting, iframe limitations, and permissions can be frustrating. If you simply need a reliable, efficient way to create, edit, and collaborate on documents without intricate web part configurations, WPS Office is an excellent choice. It provides a highly compatible and lightweight alternative to Microsoft Office.

  1. 1. Download WPS Office: Visit the official WPS website to download and install the free software suite on your device.
  2. 2. Open and Edit Files: Launch WPS Office to easily open your existing documents, spreadsheets, and presentations.
  3. 3. Save in MS Formats: Edit your files and seamlessly save them in standard Microsoft Office formats like DOCX and XLSX for easy sharing.
Seamlessly compatible with Microsoft Word, Excel, and PowerPoint formatsFree, lightweight, and fast-loading office suiteFamiliar and intuitive user interface requires zero learning curveBuilt-in PDF editing tools to streamline document sharing and collaboration
microsoft office alternative - wps office

Frequently Asked Questions

Why does SharePoint Online block my external JavaScript by default?

SharePoint Online includes a security feature called 'Custom Script' that is disabled by default on modern and self-service sites. This is designed to prevent potentially malicious external code from executing and compromising user data.

How can I check if my JavaScript file is being blocked by the browser?

You can check this by pressing F12 in your web browser to open the Developer Tools. Go to the 'Console' tab and look for red error messages. Errors stating 'Refused to load the script' or 'Blocked by CORS policy' indicate browser-level security blocks.

Can I use the Embed web part for any external script?

No. The Embed web part in SharePoint Online only allows embedding content from domains that have been explicitly approved in the site's HTML Field Security settings. You must add the external domain to the safe list before the iframe can load its resources.

Where can I get specialized support for SharePoint development issues?

For advanced development and scripting issues in SharePoint Online, Microsoft recommends posting your question in the Microsoft Q&A forum under the SharePoint tags, including your iframe markup, script URL, and tenant configuration for targeted help.