Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get previous page URL using jQuery

Tags:

jquery

How to get 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; }); 
like image 409
Geeth Avatar asked Mar 10 '10 09:03

Geeth


People also ask

How to get previous page URL in jQuery?

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

How can I see previous pages in Javascript?

If you want to go to the previous page without knowing the url, you could use the new History api. history. back(); //Go to the previous page history. forward(); //Go to the next page in the stack history.go(index); //Where index could be 1, -1, 56, etc.

How do I find the previous URL in node JS?

You have to store in session. app. get('/url1', function(req, res){ res. send('ok') req.


2 Answers

Easy as pie.

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

Hope it helps. It is not always available though.

like image 54
Marcos Placona Avatar answered Sep 19 '22 14:09

Marcos Placona


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

window.history on MDN

like image 26
Grumpy Avatar answered Sep 18 '22 14:09

Grumpy