How to add CSS and JavaScript to "_layouts/15/search.aspx" page for Sharepoint Online site

Peter 20 Reputation points
2023-02-15T17:01:46.4+00:00

We're trying to add CSS and JavaScript to "_layouts/15/searchh.aspx" page in a Sharepoint Online site to allow us to make some changes to the way the information is presented.

Is this something that can be achieved, and how? We are moving from On Premise Sharepoint servers so had this ability but we're not sure if it is possible with Sharepoint Online.

Thanks

Peter

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

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-02-16T03:22:16.4933333+00:00

    Hi @Peter,

    The Script Editor is not the build-in option in the Modern SharePoint site currently. As this article mentioned, for security reasons, modern web parts do not allow for the insertion of code like JS and css. If you are familar with codes, Script editor web part for modern pages built in React and Add The Script Editor Webpart back to SharePoint Modern Experience might be helpful for your requirement. You can learn more about spfx by following document

    https://learn.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview


    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.

1 additional answer

Sort by: Most helpful
  1. Peter 0 Reputation points
    2023-02-28T08:27:10.0266667+00:00

    Hi Raytheon Xie

    The information sounded good and its possible we will look at implementing it, however the project is very close to launch and it has been decided to concentrate on other areas for the moment as the team who would need to look at implementing the framework are at full capacity so are unable to look at this pre-launch.

    It looks like having the site content already prepared and the template and layouts in use may make it more complicated to add the script webpart to the existing pages as well as modifying the layouts to have it included.

    One of the reasons we wanted to add custom javascript was to add the script to implement Google Tag Manager/Google Analytics across the entirety of a Sharepoint Online site but we're now considering using Microsoft Clarity to implement extra analytics recording on top of the basic Sharepoint Online stats.

    We may still need to look at this pre-launch as there are some customisations we would like to do to certain pages using custom JS/CSS but these won't be clear until the new website has launched in a few weeks time.

    Thanks

    Peter


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.