Skip to content

Commit

Permalink
Fix back button when using the data-url setting
Browse files Browse the repository at this point in the history
Load a page, click a smooth scroll link, and click back. Now you should
return to the top of the page. Previously, nothing would happen.

Details here: cferdinandi#17
  • Loading branch information
robertpateii committed Dec 31, 2013
1 parent 2b1f96a commit cc70551
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion smooth-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// Function to update URL
var updateURL = function (url, anchor) {
if ( url === 'true' && history.pushState ) {
history.pushState(null, null, '#' + anchor.id);
history.pushState({pos:anchor.id}, "", '#' + anchor.id);
}
};

Expand Down Expand Up @@ -135,4 +135,11 @@

}

window.onpopstate = function(event) {
// Make back button return to top when used after clicking the first smooth scroll link.
if (event.state === null && window.location.hash === "") {
window.scrollTo(0,0);
}
};

})();

0 comments on commit cc70551

Please sign in to comment.