Others

Fix JavaScript App Not Working in Office Add-ins and SharePoint

Aamir Naveed AkramAamir Naveed Akram Sep 29, 2026 874 views

Question details

The user needs to resolve an issue where an externally hosted JavaScript application loads visually but fails to execute its interactive logic when embedded in Microsoft 365 environments.

How to Fix JavaScript Apps Not Working in Office Add-ins and SharePoint
Product
Microsoft 365
Device & OS
not provided
Scenario
Embedding an external interactive web application (like a Morse code translator) into SharePoint Online or Office for the web.
Observed behavior
The application's interface loads successfully in the frame, but the underlying JavaScript execution is blocked and the interactive features do not work.
Before you start

Before modifying your environment settings, open your browser's Developer Tools (F12) and check the Console and Network tabs for Content Security Policy (CSP) errors or iframe sandboxing blocks.

Solution 1Recommended

Initialize a Supported Office Add-in for Word and Excel

Avoid external iframe embedding restrictions by converting your web application into a native Office Add-in.

Office for the web runs embedded content in a sandboxed runtime with strict security and performance isolation. Relying on a standard iframe often blocks interactive scripts. For an interactive tool inside Word or Excel, an Office Add-in is the supported approach.

1
Configure trusted domains

Open your Office Add-in manifest file (XML or JSON format) and ensure your external application's domain is explicitly listed in the trusted domains section.

2
Add the Office.js library

Include the official Office JavaScript API script tag (<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>) in the header of your HTML file.

3
Initialize with Office.onReady()

Wrap your core JavaScript execution logic inside the Office.onReady() method to guarantee the Office runtime is fully loaded before your custom code attempts to run.

Initialize a Supported Office Add-in for Word and Excel
Developer Console Validation: After implementing Office.onReady(), reload the add-in in Excel or Word for the web and verify in the Developer Tools console that no initialization errors are thrown.
Free Microsoft Office alternative

Try WPS Office for a Hassle-Free Document Experience

Dealing with complex Microsoft Office Add-in development, SharePoint sandboxing, and strict Content Security Policies can be frustrating. If you simply need a lightweight, powerful office suite to create, edit, and share documents without the heavy administrative overhead, WPS Office is the perfect alternative.

Seamlessly compatible with Microsoft Word, Excel, and PowerPoint formats.No complex developer sandboxing or CSP setups needed for daily office tasks.Incredibly fast installation and lightweight system footprint.Free to use with a familiar, intuitive user interface that makes transitioning easy.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my JavaScript work in a normal browser but fail in a SharePoint iframe?

SharePoint Online applies strict Content Security Policies (CSP) and iframe sandboxing rules to prevent malicious scripts from executing. This often inadvertently blocks legitimate interactive logic hosted in external iframes that haven't been explicitly trusted.

How can I check if Content Security Policy is blocking my Office add-in?

Open your browser's Developer Tools (typically by pressing F12), navigate to the Console and Network tabs, and look for red error messages mentioning 'Content Security Policy directive' or 'Blocked script execution'.

What is the recommended way to add interactive JavaScript to Excel for the web?

The recommended approach is to build a native Office Add-in using the Office.js API. You must configure your app's trusted domains in the manifest and initialize the logic within the Office.onReady() function to ensure compatibility with the Office sandbox.