-1

last time i put this custom disable browser back button (Javascript) in my AMP websites page ( websites ).

I use this script to reduce the bounce rate in seo. But after requesting indexing in google search console i got some problem with "There is a required attribute missing from the HTML tag" in this script.

Does anyone know what is the solution to disable this browser back button script on AMP Pages?

<script type = "text/javascript" > history.pushState(null, null); window.addEventListener('popstate', function(event) { history.pushState(null, null); }); </script>

By the way, my page is fully custom html AMP page, so all my css, html, scripts are concatenated inside index.html file.

Websites: luckysanto.com

info indo
  • 1
  • 1
  • You really shouldn't try to change browser behavior because that results in a bad user experience. – Esger Dec 14 '22 at 19:36

1 Answers1

0

Is it a valid AMP page? As I can see your script is non-AMP so probably it's deleted by amp sanitizer. You have to run your custom JavaScript in a Web Worker in order to have a valid AMP page. Here is amp-script component documentation.

Since you can only run JS in the web worker (in other words isolated DOM), you cannot manipulate anything outside of it, most likely browser history too.

la_petite_kozel
  • 826
  • 5
  • 26