I realized that I missed the important part of sending, so I decided to configure the code to store the cookie in the click event instead of the original way of saving it when scrolling.
The jquery method is used here:
jsfiddle (Just add /show at the end of the url if you want to view it outside the frames)
It is very important that you need the jquery cookie plugin.
JQuery
// 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() ); }); });
Here's the code from the original answer:
jsfiddle
JQuery
// 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 scrolling happens.... $(window).on("scroll", function() { // Set a cookie that holds the scroll position. $.cookie("scroll", $(document).scrollTop() ); }); });
Answer to
@Cody reminded me of something important.
I just did this to check and scroll to the vertical position.
source share