title: Hide div when user clicks browser's back button
body: <p>When a user clicks a thumbnail, it opens a div that covers the whole screen, and the document title and URL both change.</p>
  
  <pre><code>$('.view-overlay').show();
  $('html,body').css("overflow","hidden");
  
  // once AJAX is done, in success:
  
  $('.view-overlay').append(data);
  window.history.pushState('page2', title, url);
  document.title = title;
  </code></pre>
  
  <p>When the user clicks the back button, I want to reverse that, with the following JS to execute:</p>
  
  <pre><code>$('.view-overlay').empty().append('&lt;div class="view-close"&gt;x&lt;/div&gt;').hide();
  $('html,body').css("overflow","auto");
  window.history.pushState('page1', "previous title", "previous url");
  document.title = "previous title";
  </code></pre>
  
  <p>I tried <code>onbeforeunload</code> but I'm not sure if that's how it can be used</p>