JavaScript on Microsoft 365 Website

PROBLEM: I want to add JavaScript to a site built in Microsoft 365/SharePoint.  However, I can't seem to do it correctly when I add it to an html web part.

SOLUTION: This took me about 3 hours to figure out, so don't do this lightly and always keep a backup of the file before you make this change.  There might be an easier way to do this, but I couldn't get anything else to work. (I had to install Microsoft Share Point Designer onto my computer. I am not going to go into the details of all of that.)

  • Click on ALL FILES in the lefthand sidebar.
  • Click on PAGES.
  • Click on the FILENAME on the righthand side.
  • Right-click on the file and click CHECK OUT.
  • Click on EDIT FILE WITH at the top and open with Notepad.
  • This is where it gets tricky.  The file will not have any line breaks, so you need to make sure you put code in the right place. I usually do a FIND to get to the right place. Be aware you probably won't see anything outside of the body area.
  • Add the code to the notepad file after the first asp line which signifies the start of the content.
  • SAVE the file.
  • Right-click on the file and click CHECK IN. It should update on the server.
  • Refresh the page to see the changes.

PLEASE NOTE: You are going to have to do this page by page.  The headers and footers are created dynamically and I haven't figured out how to do any edits globally. (Though I am sure there is probably a secret way.)

WHY: I think it is because Microsoft wants to retain some control on people's websites, but also because they don't want people who do not know what they are doing to make a severe error which might include a security risk. It is stupid because people who do not know what they are doing shouldn't even be using this software.

ADVICE: I am not a fan of this website builder.  It is exceedingly complicated and buggy.  I would not recommend that Microsoft 365 be used for small business or personal websites. Yes, I know it is cheap, but that doesn't always mean it is a good idea. Please consider WordPress.  It is much more user-friendly and flexible.