SOLVED

Insert script in the header of the Modern page- SharePoint Online

Copper Contributor

Hi,

 We are redesigning our intranet and upgrading to the Modern SharePoint site. One of the requirements is to insert a script in the header and div tag on the homepage.  How do I go about setting this ? The script and HTML tag are only loaded on the homepage, we don't plan to use them on other pages. It is a social feed from Curalate (Approved Instagram images).

 

Any help is appreciated. 

Thanks

7 Replies
best response confirmed by Pbala (Copper Contributor)
Solution

@Pbala If you want to a insert script only on single modern site page, you can use Modern script editor web part developed by community members.

 

Check below links for script editor web parts (developed using SPFx):

  1. react-script-editor
  2. Modern CEWP by SPJS

Also, check my answers given in below links about how to use these web parts:

  1. SharePoint Online and adding an interactive page (Javascript) 
  2. Current user context in SharePoint modern page 

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Hello,

I would recommend creating a SPFx Extension webpart.

Yours sincerely,
Aref Halmstrand
Thanks Ganesh, I will try this out. Question is can I add the script tag to a modern page header ?
Thanks
Pbala
The extension can show up as a header.

Yours sincerely,
Aref Halmstrand

@ArefHalmstrand do you have a link on a tutorial to do that?

@Marco Friedmann 

 

I used the Modern CEWP to insert script.  It worked great for me.

https://spjsblog.com/modern-cewp/

Once you install in your environment, it will be available as a below when u add a webpart.

Pbala_0-1645547811270.png

And add your code here...

 

Pbala_1-1645548024727.png

Hope this helps.

1 best response

Accepted Solutions
best response confirmed by Pbala (Copper Contributor)
Solution

@Pbala If you want to a insert script only on single modern site page, you can use Modern script editor web part developed by community members.

 

Check below links for script editor web parts (developed using SPFx):

  1. react-script-editor
  2. Modern CEWP by SPJS

Also, check my answers given in below links about how to use these web parts:

  1. SharePoint Online and adding an interactive page (Javascript) 
  2. Current user context in SharePoint modern page 

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

View solution in original post