title: Using jQuery to store scroll position, works well. How do I allow ONLY for refresh's, not new page requests?
body: <p>I'm using this code I found elsewhere on SO:</p>
  
  <pre><code>// When document is ready...
  $(document).ready(function() {
  
  // If cookie is set, scroll to the position saved in the cookie.
  if ( $.cookie("scroll") !== null ) {
      $(document).scrollTop( $.cookie("scroll") );
  }
  
  // When a button is clicked...
  $(':submit').on("click", function() {
  
      // Set a cookie that holds the scroll position.
      $.cookie("scroll", $(document).scrollTop() );
  
  });
  
  });
  </code></pre>
  
  <p>I have the cookie.js file, and the code works wonderfully. However, I'd like to have it so that this code only executes <i>after</i> a submit... right now, it will move to the last scroll position on every load, which is not what I want.</p>
  
  <p>Obviously I can't clear the cookie on <code>$(document).ready</code>, because the code wouldn't do anything at all, right? Any ideas?</p>
  
  <p>EDIT - </p>
  
  <p>Tried this code, but no dice (now it doesn't work at all):</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(document).ready(function() {
  $(':submit').on("click", function() {
  
   $.cookie("scroll", $(document).scrollTop() );
  
       if ( $.cookie("scroll") !== null) {
           $(document).scrollTop( $.cookie("scroll") );
           $.cookie('scroll', null, { path: '/' });
       }
   });
  
  });
  &lt;/script&gt;
  </code></pre>