3

I have a classifieds website. And there are 3 main pages

1) Location selector page
2) Listing page (where ads are listed)
3) And Details page, where details about ads displayed

The URLs of details page are user-friendly-URLs.

What I want is,

If user clicks on links on Google search results (URLs of details page), I want the user to redirected to Ads page

But if user type-in URL in browser then I want user to go to Location Selector page.

My question is: Is there a way I can differentiate how user hit my website (from typing URLs in browser OR clicking on Google search results)?

I am using Asp.net with C#. .Net framework 4.0.

I know I can use Request.UrlReferrer.ToString() to retrieve URL of previous page of the same application.

But how to get previous page if previous page is search result of Google or Bing or some other search engine. And how to find out if there is no Previous page, i.e. if user typed URL in browser?

I want solution that works in all browsers

user786
  • 3,902
  • 4
  • 40
  • 72
  • 2
    Request.UrlReferrer should be set when clicking from a search result, all you should have to do is parse the the string for the search query. If url is typed in the UrlReferrer should be empty. Are you seeing something different? – Patrick Evans Aug 20 '15 at 14:05
  • 1
    try `document.referrer` – shreesha Aug 20 '15 at 14:29

1 Answers1

3

try using document.referrer to get previous url.

it returns the referrer of the current document.
document.referrer gives you the URI of the page that linked to the current page. This is a value that's available for all pages, not just frames. check the link for better understanding

Community
  • 1
  • 1
shreesha
  • 1,811
  • 2
  • 21
  • 30