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

159
Views
How to trigger a specific task when Back Button is clicked in Browser EVERYTIME?

I m trying to trigger a specific task, like change the CSS of the element when every time user clicks on the browser's Back button.

Luckily SO got my back with the code below, which triggers when a user clicks on the back button and dees the task.

But however, this trigger on the back button click only works once per page load. Hence, the function().

Can anyone help me with how to make it get triggered whenever the back button is pressed?

Code goes as :

$(function() {
    if (window.history && window.history.pushState) {
        window.history.pushState('', null, './');
        $(window).on('popstate', function() {
         // My stuff
        });
     }
});

Any help is greatly appreciated.

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

0

Use event listener , i dont know how to do it in jQuery, the code will look like this

    if (window.history && window.history.pushState) {
        window.history.pushState('', null, './');
        window.addEventListener('popstate', function() {
         // My stuff
        });
     }
});

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!