1

I am trying to add a piece of JS code to a SharePoint Online list but I have difficulty getting it done. The purpose of this code is to show a disclaimer.

I have added the below code after the "body" tag in all of the four master files (as shown below) but this did not work. When I added it to seattle.master it enabled the pop-up but not in a list, the pop-up was enabled when I was in the "list setting" page or similar pages, but not on the list page.

    <script type="text/javascript"> 
if (confirm('Are you sure you want to save this thing into the database?')) {
  // Save it!
 console.log('Thing was saved to the database.');
} else {
 // Do nothing!
 console.log('Thing was not saved to the database.');
 }
   </script>
   <br>testttttttttttt</br>

enter image description here

1 Answer 1

1

The way you add the custom pop up js code only works for classic pages, it would not affect modern pages(list page).

If you click Return to classic SharePoint, it will work in classic list page.

To add custom code to modern page, you need to develop SharePoint Framwork: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview

2
  • 1
    Thanks, you mean if I use sharepoint designer and inject the JS there, it works when the list is in the classic mode and if I change it to modern, the JS stops working, right? Re spfx, I found this sharepointpals.com/post/…, is this a correct guide that I need to follow? Aug 25, 2021 at 6:47
  • 1
    Yes, inject js code in master page only works for classic experience. For modern page, you need to use SPFx to customize and that blog would be helpful, you could have a try. Aug 25, 2021 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.