question

RomanKorchak-9668 avatar image
0 Votes"
RomanKorchak-9668 asked MichaelHan-MSFT commented

Inject javascript into SharePoint online communication site

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

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

trevorseward avatar image
0 Votes"
trevorseward answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @RomanKorchak-9668 ,

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Hi @RomanKorchak-9668 ,

Is there anything update? If there is any answer helps you, please click "Accept Answer" and upvote it.

0 Votes 0 ·