Fix SharePoint Online Iframe Cannot Import External JavaScript File
Question details
The user is unable to load or execute an external JavaScript file within a custom HTML iframe in SharePoint Online.

- 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.
Ensure you have Site Administrator privileges in SharePoint Online, as you may need to check or modify site security configurations and HTML field settings.
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.
Log in to Microsoft 365 and open the SharePoint Admin Center using an administrator account.
Click on 'Settings' in the left-hand navigation menu, then select 'classic settings page' at the bottom.
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'.
Click 'OK' to save. Note that it may take up to 24 hours for this change to take effect across your SharePoint tenant.

Resolve CORS and Mixed Content Errors
Browsers strictly block scripts that violate Cross-Origin Resource Sharing (CORS) policies or load unsecure HTTP scripts on HTTPS pages.
Update HTML Field Security
SharePoint's HTML Field Security prevents iframes from loading content from unauthorized external domains.
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. Download WPS Office: Visit the official WPS website to download and install the free software suite on your device.
- 2. Open and Edit Files: Launch WPS Office to easily open your existing documents, spreadsheets, and presentations.
- 3. Save in MS Formats: Edit your files and seamlessly save them in standard Microsoft Office formats like DOCX and XLSX for easy sharing.

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.




