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

271
Views
how to detect if window was refreshed or closed in js?

i know this question was asked before but i, can't get this to work.

I have a .aspx which contains a function on the onunload body tag. This will refresh the parent page.

At this point, i need to know if the page was refreshed/reloaded, because this logic will trigger the func call everytime and close my "child" page.

This is my code

<script type="text/javascript">
    function refreshparent(){
        window.opener.location.reload(true);
        window.close();
    }
</script>

This is whay i want to do

<script type="text/javascript">
    function refreshparent(){
      if(page.wasclosed){
        window.opener.location.reload(true);
        window.close();
      }else{
   //do nothing
      }
    }
    </script>

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can try something like this


window.onload = function () {
      if (!window.location.hash) {
        window.location = window.location + '#loaded';
        window.location.reload();
      }
    }

once the page refreshed the #loaded is added to the url and once #loaded us detected it stops refreshing meaning "true". then you can use search params anywhere to see if the page was reloaded. You can add this in a setTimeout function or something else.

about 4 years ago · Santiago Trujillo 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!