You can try add an html component to a global element (such as site header), and put this code inside. Maybe it’ll work.
On side note: I think disabling the browser back is a terrible UX.
But doing that will disable the back button on all my pages, which will ruin the UX. I only want to do that on some subpages that my site has. How can I do that?