tags:

views:

380

answers:

4

Hi,

How to get the previous page url using jquery?

I am using the following code to get the current page location

$(document).ready(function() {
var pathname = window.location.pathname;
});
+1  A: 

Easy as pie.

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

Hope it helps

Marcos Placona
Note to Geetha: document.referrer is plain old JavaScript, so that might the reason that you can't find it browser the jQuery docs.
Jan Aagaard
True.. Plain'ol JS ftw :-)
Marcos Placona
A: 

do you mean history(-1); ?

Grumpy
A: 
var from = document.referrer;
console.log(from);

document.referrer won't be always available.

Amarghosh
A: 

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 :)

epiece