Q:

Get previous URL and display on page in Javascript

I have a jobs website with several different job description pages and with 1 application page with a form.
i.e.
/admin-clark -> /application
/sale-rep -> /application

I would like to pre-populate an input field in the form with the id #jobTitle.
I would like to do the following-

Get the previous URL
Store it in local storage
Sanatize url(remove dashes etc)
Use jQuery to fill in the field with id jobTitle

Or is a there a better way of doing this?
This is what I have so far
var pathname = window.location.path.replace(/^\?$/, '').toUpperCase();
localStorage.setItem("pathname ", pathname );
$('#jobTitle').val(pathname);

A:

in many cases(Not in every case) will get you the URL of the last page if they got to the current page by clicking a link using document.referrer; See here
You can also take help from here

