Capture previous URL in hidden field
Script for capturing the page URL that loaded the current page. It only works if the page was opened through a link (if opened through a bookmark or redirect it returns an empty string).
<!-- START code for adding referrer URL to a hidden field -->
<script>
$(document).ready(function() {
var referrerUrl = document.referrer;
var fieldLabel = 'referrer';
$('input[name="' + window.btoa(fieldLabel) + '"]').val(referrerUrl);
});
</script>
<!-- END code for adding referrer URL to a hidden field -->