Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
¿Cómo evitar que history.back() regrese al sitio web externo?

Así que estoy tratando de hacer un botón Atrás usando onclick="history.back()" . Pero la cuestión es que cuando entro en mi sitio web usando un enlace externo y presiono el botón Atrás, me lleva de vuelta a la página anterior que es externa. Sé que ha sido programado para hacerlo. Pero, ¿hay alguna forma de evitar que los usuarios regresen al sitio web externo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Una forma sería almacenar en sessionStorage el valor history.length que recibió cuando visitó la página por primera vez.

Luego almacenará el índice actual en history.state . Una vez que vuelva al índice inicial, evitará que el historial retroceda.

 // To be executed on all the pages of your domain // check if we already saved it let min_index = sessionStorage.getItem("minHistoryIndex"); // otherwise if (min_index === null) { // store it min_index = history.length; sessionStorage.setItem("minHistoryIndex", min_index); } // first time we come to this history status if (!history.state ) { history.replaceState({ index: history.length }, ""); } const button = document.querySelector("button"); // if we reached the limit saved in sessionStorage if (history.state.index === +min_index) { button.disabled = true; button.title = "Going back once more would take you out of our website"; } else { button.onclick = (evt) => history.back(); }

Demostración en vivo - fuente

Un problema con esto es que si su usuario decide ir a otro origen desde su página y luego volver a él manualmente, podría volver a ese dominio externo, pero supongo que es un caso tan extremo que puede aceptarse en mayoria de los casos.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!