Skip to content

Instantly share code, notes, and snippets.

@schjetne
Created April 24, 2013 12:12
Show Gist options
  • Save schjetne/5451674 to your computer and use it in GitHub Desktop.
Save schjetne/5451674 to your computer and use it in GitHub Desktop.
Code to navigate to previous page in history if it exists, otherwise go back to a default "back" location.
// Use: ><a href="list.html" class="js-back">Go back</a>
$('.js-back').on('click', function(evt) {
if (document.referrer != "") {
evt.preventDefault();
history.back();
}
});
@namnguyen2091
Copy link

first solution doesn't work, @Pistil-Studio may be ok

@johnmugabe
Copy link

Thanks @Pistil-Studio. Works perfectly

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