Yannick
Yannick

Reputation: 235

Redirect based on last visited website

At the moment i'm trying to make a new script that is based on the last visited website of the user. If last visited website is x, then it needs to redirect to another page.

Example: User clicks on a link on my Facebook fan-page and lands on the homepage. The Javascript now needs to take an action and redirect the user to another page. But only if the user came from http://facebook.com/[fanpage]

Is it possible to create something like this in Javascript?

Thanks a lot,

Upvotes: 1

Views: 213

Answers (3)

ComFreek
ComFreek

Reputation: 29434

I wouldn't rely on referrers sent by the browser. They can be turned off.

Why don't you pass a special parameter in your URL?

http://www.example.com/?fromFb=1

Upvotes: 1

insertusernamehere
insertusernamehere

Reputation: 23590

You could use document.referrer like this:

if ('http://facebook.com/[fanpage]' == document.referrer) {
    location.href = 'new_destination.html';
}

Upvotes: 2

Ry-
Ry-

Reputation: 225044

If Facebook doesn't do some kind of referrer blocking, then use document.referrer to get the referring page.

(It sounds like that might be something better accomplished server-side, though, in which case you would use the Referer [sic] header.)

Upvotes: 1

Related Questions