Last active
January 9, 2019 01:29
-
-
Save atomita/afaf21ba2513cdc4e22ed6af94252db8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const prevPage = document.referrer | |
| if (origin(createAnchor(prevPage)) === origin(window.location)) { | |
| window.history.pushState(location.href, '', '/') | |
| } else { | |
| window.history.back() | |
| } | |
| function createAnchor(url) { | |
| const anchor = document.createElement('a') | |
| anchor.href = url | |
| return anchor | |
| } | |
| function origin(loc) { | |
| var protocol = (loc.protocol && ':' !== loc.protocol) ? loc.protocol : location.protocol | |
| var host = [loc.hostname, parseInt(loc.port, 10) === 80 ? 0 : loc.port].filter(Boolean).join(":") | |
| || [location.hostname, parseInt(location.port, 10) === 80 ? 0 : location.port].filter(Boolean).join(":") | |
| return protocol + "//" + host | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment