Skip to content

Instantly share code, notes, and snippets.

@henrytran9x
Created December 9, 2015 04:46
Show Gist options
  • Save henrytran9x/d6584b362f0bdac15782 to your computer and use it in GitHub Desktop.
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
// 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);
@henrytran9x
Copy link
Author

Note: this example makes use of https://github.com/carhartl/jquery-cookie Plugin by Klaus Hartl, so make sure you include it, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment