title: How to reload a webpage with a button click in javascript but after reload calling a function
body: <p>I am making a flash gallery and I would like the page to reload every time a new flash is displayed on the page. I would like to do this because I would like to increase the amount of ads displayed per user visit. The button clicks successfully reload the page but stops the future code from firing which is what displays the flash. </p>
  
  <pre><code>var c = 0;
  var flashcon, test, temp;
  
  // Function for inital flash page to work properly
  function init() {
      flashcon = document.getElementById('flashcon');
  
      // Scripts for the buttons
      document.getElementById('back').onclick = function () {
          location.reload(false);
          if (c == 0) {
              c = paths.length;
          }
          c--;
          displayFiles();
          download();
      }
  
      document.getElementById('next').onclick = function () {
          location.reload(false);
          if (c == paths.length - 1) {
              c = -1;
          }
          c++;
          displayFiles();
          download();
      }
  
      document.getElementById('rand').onclick = function () {
          location.reload(false);
          temp = c;
          while (c == temp) {
              c = Math.floor(Math.random() * paths.length);
          }
          displayFiles();
          download();
      }
  
      // Scripts for the left and right arrow key functionality
      document.addEventListener('keydown', function (e) {
          if (e.which == 37) {
              $("#back").click();
          }
      });
  
      document.addEventListener('keydown', function (e) {
          if (e.which === 39) {
              $("#next").click();
          }
      });
  }
  </code></pre>