Created
December 4, 2014 19:05
-
-
Save simonrjones/9ebe1d02cc582e693c66 to your computer and use it in GitHub Desktop.
JavaScript back to last page link
This file contains 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
// Go back link functionality | |
// Requires HTML link with id="back-to-last-page" which is hidden by default with display: none; | |
if (window.history && window.history.pushState) { | |
// Only display if referrer matches current hostname | |
var matchHostname = new RegExp('http(s)?:\/\/' + window.location.host); | |
if (matchHostname.test(document.referrer)) { | |
// Show link and go back via History API | |
$('#back-to-last-page').show(); | |
$('#back-to-last-page').click(function (e) { | |
window.history.back(); | |
return false; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment