How to get previous page url using jquery

Do you mean something like history.go(-1);? It will go back to the previous page.

window.history on MDN


If you are using PHP, you can check previous url using php script rather than javascript. Here is the code:

echo $_SERVER['HTTP_REFERER'];

Hope it helps even out of relevance :)


var from = document.referrer;
console.log(from);

document.referrer won't be always available.


Easy as pie.

$(document).ready(function() {
   var referrer =  document.referrer;
});

Hope it helps. It is not always available though.

Tags:

Jquery