window.history.pushState(null, null, location.href); window.addEventListener('popstate', () => { history.go(1); alert('Back button is not allowed.'); });Mostrar el mensaje cuando se hace clic en el botón Atrás del navegador en Chrome y la última versión de Edge sobre el fragmento de código no funciona.
En Firefox funciona perfectamente.
Por favor sugiera cualquier solución.
Intente ejecutar este código y luego use el botón Atrás del navegador.
<script> (function (global) { if (typeof global === "undefined") { throw new Error("window is undefined"); } var _hash = "!"; var noBackPlease = function () { global.location.href += "#"; // making sure we have the fruit available for juice.... // 50 milliseconds for just once do not cost much (^__^) global.setTimeout(function () { global.location.href += "!"; }, 50); }; // Earlier we had setInerval here.... global.onhashchange = function () { if (global.location.hash !== _hash) { global.location.hash = _hash; } }; global.onload = function () { noBackPlease(); // disables backspace on page except on input fields and textarea.. document.body.onkeydown = function (e) { var elm = e.target.nodeName.toLowerCase(); if (e.which === 8 && elm !== "input" && elm !== "textarea") { e.preventDefault(); } // stopping event bubbling up the DOM tree.. e.stopPropagation(); }; }; })(window); </script> <script src="http://static.jsbin.com/js/render/edit.js?4.1.8"></script> <script> jsbinShowEdit && jsbinShowEdit({ static: "http://static.jsbin.com", root: "http://jsbin.com", }); </script> <script> (function (i, s, o, g, r, a, m) { i["GoogleAnalyticsObject"] = r; (i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments); }), (i[r].l = 1 * new Date()); (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })( window, document, "script", "https://www.google-analytics.com/analytics.js", "ga" ); ga("create", "UA-1656750-34", "auto"); ga("require", "linkid", "linkid.js"); ga("require", "displayfeatures"); ga("send", "pageview"); </script>