I use the SharePoint Online Modern Experience.

I am trying to run Javascript in my sharepoint online page but it will not run. It runs on my computer however and correctly displays the resultant page.

This is my HTML file called test.html. It is both on my computer and SharePoint online:

<h1>The script element</h1>
    <p id="demo"></p>
    document.getElementById("demo").innerHTML = "Hello JavaScript!";

As mentioned above it runs and displays correctly on my computer like so:
enter image description here
I created a SharePoint page and used the Embed web part to reference this HTML file using iFrame. My iFrame code is like so:

<iframe id="inlineFrameExample" title="Inline Frame Example" width="300" height="200" src="path to above HTML file">

Unfortunately, the javascript script is not run; "Hello JavaScript!" is not displayed. This is what is displayed on the sharepoint online web page
enter image description here

How do I get the javascript to execute?

  • You cannot load an HTML page this way… Also you may want to look at the error messages showing up in the Developer Toolbar. But I think the Embed webpart is not here to do what you're trying to do…
    – AymKdn
    Commented Jan 25, 2023 at 13:42
  • So how do I get my javascript script to run ?
    – John Doe
    Commented Jan 25, 2023 at 23:48
  • Look at this other thread sharepoint.stackexchange.com/questions/305886/…
    – AymKdn
    Commented Jan 26, 2023 at 8:05

1 Answer 1


Use SharePoint Framework (SPFx) Extension: SharePoint Framework (SPFx) is a powerful development framework that allows you to build custom solutions for SharePoint Online. With SPFx, you can create an extension that references your local JavaScript files and deploy it to SharePoint Online.

You can also try deploying the script editor web part which is available in the community

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.