Inject javascript into SharePoint online communication site

Roman Korchak 1 Reputation point
2020-12-05T08:10:13.607+00:00

Hi All
I need to inject some javascript into all sharepoint online site collection pages. I managed to do it in Team site by adding javascript file link in to a master page, but cannot find the way to do it in communication site. I found master page in communication site and managed to add my javascript file link to it, but it seems to only work on system pages (sharepoint site settings etc) . I did see some articles where its done by creating SPFX sharepoint app and importing it into the site, but doing all that just to add few lines of javascript (comparing to just adding a link into master page) seems crazy .
Thanks

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

2 answers

Sort by: Most helpful
  1. trevorseward 11,711 Reputation points
    2020-12-05T16:00:26.297+00:00

    Javascript injection is something that was removed with modern site designs. Instead, you should look at using a SharePoint Framework app to accomplish the desired goal.

    Masterpages are not used in modern sites.

    0 comments No comments

  2. MichaelHan-MSFT 18,126 Reputation points
    2020-12-07T06:55:06.787+00:00

    Hi @Roman Korchak ,

    As trevor said, master page is only used for classic pages. The customizations in master page only works for classic page. It would not affect the modern page.

    For modern sites, you have to create SPFX sharepoint app to achieve this.

    The below SPFx app would help you inject css/js file to SharePoint modern pages: https://github.com/hugoabernier/react-application-injectcss


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.


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.