Created
December 9, 2015 04:46
-
-
Save henrytran9x/d6584b362f0bdac15782 to your computer and use it in GitHub Desktop.
Run a JavaScript only on the First Page Load / only on Succeeding Page loads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Note: this example makes use of jquery.cookie Plugin by Klaus Hartl, so make sure you include it, too. | |
| (function ($) { | |
| $( document ).ready(function() { | |
| var cookieName = 'firstPageLoad'; | |
| var cookieValue = 1; | |
| // if the cookie doesn't exist we're on the first page load... | |
| if (!$.cookie(cookieName)) { | |
| // and set a cookie that is valid for the entire domain | |
| $.cookie(cookieName, cookieValue, { path: '/'}); | |
| } | |
| // if the cookie does exist, its (most probably) a succeeding page load... | |
| else { | |
| // ... so we want to scroll to the navigation | |
| $('html, body').animate({ | |
| scrollTop: $("#navigation").offset().top | |
| }, 1000); | |
| } | |
| }); // document ready | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this example makes use of https://github.com/carhartl/jquery-cookie Plugin by Klaus Hartl, so make sure you include it, too.