Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, having trawled the net, I cant find an absolute answer, so am hoping you can help.
I am building a corporate web site that has a variable strap line / message on the home page. At the moment the message is randomly generated and may not therefore relate to what a visitor is interested in.
What I want to do is examine the URL of the referring page to see if there are any clues as to why the Visitor has come to the site, and if there are to present them with a suitable message pointing them in the right direction.
I have tried request.getHeader("referer"), but this only seems to work for internal links and not for links in from say a Google Search.
So for instance, if we were able to pick up the following URL "http://www.google.co.uk/search?hl=en&source=hp&q=staplers&btnG=Google+Search&meta=&aq=f&oq=", then we could detect the word "staplers" in the middle and present a message relating to Staplers to the Visitor.
No I don't sell Staplers, it was the first example that came to mind !!!
So how do I get the Full URL of the Previously visited page ?

Hi, have you also tried:
if (document.referrer.indexOf('staples') != -1) {
// write-code-to-display-your-staples-info
}

I dont have a problem with the logic around how to display my message. My question was more about how I get the URL.
That looks like a JavaScript snippet as opposed to Java code in a JSP, I am not averse to that, but would "document.referrer" using my example return
"http://www.google.co.uk/search?hl=en&source=hp&q=staplers&btnG=Google+Search&meta=&aq=f&oq="
or
"http://www.google.co.uk"
Obviously the latter would be of no use to me at all.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |