2

is it possible to in javascript like in php header location, if the visitor comes from index html alert something? and how ? thank you

2
  • 3
    Can you clarify that question a bit? At the moment people will be guessing at what you're asking. Commented Jun 29, 2010 at 14:17
  • I think he is talking about the REFERER: if visitors come from index.html, alert something. In that case, use the History object. Commented Jun 29, 2010 at 14:19

2 Answers 2

2
if(document.referrer == url){ alert(msg); }

Should do it.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Wow. Had never heard of that, works in Chrome, IE7, and Firefox at least.
2

Check the referrer, but you most likely will need the absolute uri, like this:

if (document.referrer == 'http://domain.com/index.html')
    alert('How was the index?');

1 Comment

You could of course use the match() method like so if(document.referrer.match("index.php")){ alert(msg) }, but as you rightly say full URL is probably the best idea since it will prevent cross domain matches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.