Javascript does not work when HTML file is opened from Sharepoint library

Rajashree Kamath Bola 1 Reputation point
2022-07-28T07:33:56.403+00:00

The html file has window.print().
When we open file from sharepoint library, the print dialog box doesnt appear. Looks like scripts are unable to run.
Please help!!

Microsoft 365 and Office SharePoint For business Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,251 Reputation points
    2022-07-29T07:09:08.55+00:00

    Hi @Rajashree Kamath Bola ,

    According to my research and testing , when we open the HTML file in the SharePoint Library, only the part of the HTML can be displayed, and JavaScript does not work, unfortunately, it is by default. As a workaround, you can input your code in Script Editor web part, and the JavaScript will working in the web part. You can follow these steps:

    1.Go to Page ->>Click "New" ->> Click "Wiki Page"
    List item
    2.Click "INSERT" ->> Web Part ->> Media and Content ->> Script Editor ->>Click "Add"
    226022-02.png
    3.Click "Edit Web Part"
    226083-image.png
    4.Click "EDIT SNIPPET"
    225996-image.png
    5.Input your code and Click "Insert" ->> Click "OK" ->>Save the page

    My test result (In my test, JavaScript works well) :
    226040-03.png

    Hope it can help you. Thanks for your understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.