Get Keyword and Redirect

Is it possible in JavaScript to grab the keyword phrase that people use to enter a website from a search engine or paid search engine. Then use that data to redirect the visitor to the correct page on the website depending on the keyword phrase?

For example if keyword 1 contains “word1” in the keyword phrase automatically redirect to page1.html. If keyword 2 contains “word2” in the keyword phrase automatically redirect to page2.html.

Does anyone know how to do this? Any help would be greatly appreciated!

I believe that document.referrer can provide that info.

How can document.referrer be used?

You use document.referrer to retrieve a string that contains the path the person came from.


var referrer = document.referrer;

Which in the case of my viewing this particular thread, is:
http://www.sitepoint.com/forums/forumdisplay.php?f=15

Then you use standard string manipulation techniques to retrieve the information you want from that string.