how to avoid refresh page javascript code example

Example 1: prevent reload javascript

window.onbeforeunload = function() {
  return "Dude, are you sure you want to leave? Think of the kittens!";
}

Example 2: how to refresh a web page automatically in javascript

<html>
   <head>
      
      <script type = "text/JavaScript">
         <!--
            function AutoRefresh( t ) {
               setTimeout("location.reload(true);", t);
            }
         //-->
      </script>
      
   </head>
   
   <body onload = "JavaScript:AutoRefresh(5000);">
      <p>This page will refresh every 5 seconds.</p>
   </body>
   
</html>

Example 3: javascript reload page without refresh

<a href="javascript:window.top.location.reload(true)" class="continue">Continue</a>