With html 5 you can use history API.
history.pushState({
prevUrl: window.location.href
}, 'Next page', 'http://localhost/x/next_page');
history.go();
Then on the next page you can access state object like so
let url = history.state.prevUrl;
if (url) {
console.log('user come from: '+ url)
}