How to inject Javascript file in to sharepoint master page without modifying it

Shiva Krishna Pathem 1 Reputation point
2021-04-18T03:56:43.63+00:00

Hello Team,

I am trying to inject java script file into sharepoint master page without modifying/opening the master page. tried many solutions but not working.

Tried 'Add-PnPJavaScriptLink' and 'Add-PnPJavaScriptblock' this two as well but not luck.

Requesting your assistance on the same.

Thanks & Regards,
Shiva Krishna

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

1 answer

Sort by: Most helpful
  1. ZhengyuGuo 10,586 Reputation points Moderator
    2021-04-19T02:09:51.527+00:00

    Hi @ShivaPathem-4926 ,

    "Add-PnPJavaScriptLink" and "Add-PnPJavaScriptblokc" are only valid for class site experience.

    If it's the Modern site, then it's suggested to use SPFX Application Customizer Extension for injecting, here is a step by step demo for your reference:

    Step By Step Procedure To Add A JS File To All Pages In A SPFx Modern Pages Using SharePoint Framework Extension

    Thanks
    Best Regards


    If the response 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.

    0 comments No comments

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.