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

228
Views
Prevent page refresh when browser back button hits

I need to prevent page refresh when back button clicks in my wordpress application. I tried some solutions available online, but no use.

Here is my code in functions.php

<script>
    console.log(123)
    $(window).on('popstate', function(event) {
       console.log("pop");
    });
</script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

window.onhashchange = function() {
   //blah blah blah
}

You can use this for more info read this answer How to Detect Browser Back Button event - Cross Browser

or you can use this

window.onbeforeunload = function() { return "Your work will be lost."; };
about 4 years ago · Juan Pablo Isaza Report

0

You can use pageshow event to handle browser navigation through your page history

Use this code may it's Works for you

window.addEventListener( "pageshow", function ( event ) {
  var pageHistory = event.persisted || 
                         ( typeof window.performance != "undefined" && 
                              window.performance.navigation.type === 2 );
  if ( pageHistory ) {
    // Handle page restore.
    window.location.reload();
  }
});
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!