0

Example.

User was in /home.html

redirected to /room.html

press back button in browser(or backspace) -> came back to /home.html

is there a javascript or jquery function to fecth the previous page url?(/room.html)

Canna
  • 3,614
  • 5
  • 28
  • 33
  • Useful thread http://stackoverflow.com/questions/3528324/how-do-you-get-the-previous-url-in-javascript – melc Dec 10 '13 at 10:31
  • You can tell the browser to go back/forward, but you can't get the url's in the history. Check out this question http://stackoverflow.com/questions/1232863/get-full-url-history-using-javascript – jcvandan Dec 10 '13 at 10:31

3 Answers3

0

You can use document.referrer to get that.

string url = document.referrer;

Description: Returns the URI of the page that linked to this page.

The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark). Since this property returns only a string, it does not give you DOM access to the referring page, Referance.

Adil
  • 146,340
  • 25
  • 209
  • 204
  • ok so this is how it works. home -> room // it shows home.html , but room -(backbutton)- home /// doesn't show room.html – Canna Dec 10 '13 at 10:31
0

is there a javascript or jquery function to fecth the previous page url?(/room.html)

window.history.back() returns you to the previous page

window.history.forward() goes forward

check out the window.history object

user1021726
  • 638
  • 10
  • 23
0

The back() method loads the previous URL in the history list.

This is the same as clicking the "Back button" in your browser, or history.go(-1)

window.history.back()
sumit
  • 15,003
  • 12
  • 69
  • 110