Created
June 8, 2018 03:45
-
-
Save weird-coon/33229493d7f7391be18f7e88a9ac9f16 to your computer and use it in GitHub Desktop.
[JS] Redirect to previous page
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
/** | |
* Redirect to previous page | |
* | |
* @returns {boolean} | |
*/ | |
function redirect_back() { | |
// From other domain or from direct | |
if (document.referrer.split('/')[2] != location.hostname) { | |
location.href = '/'; | |
} else { | |
// From another page in our site | |
window.history.back(); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment