0

In this code:

if (screen.width <= 800) {
    window.location = "http://www.megaoferta.bg/mobile";
}

How can I identify the URL from whom the page is opened with JavaScript?

For example, if people get to my page from a Google search, how can I obtain the page "google.com" using JavaScript?

larrydalmeida
  • 1,570
  • 3
  • 16
  • 31
Venelin
  • 2,905
  • 7
  • 53
  • 117
  • 1
    as a side note, never use `window.location` ... use `window.location.href`. it has nothing to do with answering the question, just would be remiss if i didnt mention it.3 – PlantTheIdea Dec 15 '14 at 17:21
  • http://stackoverflow.com/questions/2415633/how-to-get-previous-page-url-using-jquery –  Dec 15 '14 at 17:22

1 Answers1

6

You can use the document referrer:

var x = document.referrer;
SeanLF
  • 131
  • 2
  • 7