0

Before when I used SharePoint 2013, opening HTML files would open up in the browser and my JavaScript code works. Recently, my organization switched to SharePoint Online and I noticed the HTML files in my Site Assets were opening up in a Previewer and none of the JavaScript code works. I've tried changing the extension to .aspx but that just force downloads the file. How can I get my HTML files to open in the browser and have my JavaScript code work in SharePoint Online?

1
  • If I understand correctly, you want to integrate your own HTML and JavaScript on a page?
    – Christoph
    Sep 3, 2021 at 12:42

2 Answers 2

0

Not Sure if you have been moved SharePoint online to Modern sites and Classic Sites. Below are the approaches to use Custom JS.

With Modern Sharepoint Site Pages:

Modern Sharepoint Pages does not support integrating Custom JS code directly. You must have to use modern script editor web parts Like react-script-editor OR Modern CEWP by SPJS and add your custom JavaScript code.

With Classic Sharepoint Site Pages:

when you are using classic Sharepoint pages on the Team site then you should enable custom scripts from Sharepoint Admin Center in your tenant and use Content editor OR Script editor web part.

I hope this solution should work for you.

0

I agree with Sajid Khan.

You can preview the custom JS files(ex: html file) that uploaded to the Document Library in SharePoint Online, but you cannot execute JavaScript code.

According to my research, SharePoint Online does not support integrating Custom JS code directly.

enter image description here

enter image description here

  • On the Classic experience: You can use Content Editor web part or Script Editor web part.

enter image description here

enter image description here

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.