Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

352
Visualizações
disabled browser back button google chrome and edge
window.history.pushState(null, null, location.href);

window.addEventListener('popstate', () => {
    history.go(1);
    alert('Back button is not allowed.');
});

Show message when browser back button clicked on chrome and edge latest version above code snippet is not working.

On Firefox it works perfectly.

Please suggest any workaround.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try running this code and then use browser back button.

<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>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda