The situations where this ServerVariable works include the following methods of a browser loading a URL:
- clicking on a straight HTML <a href> link;
- submitting a form, using POST or GET, from a submit button, <input type=image> or client-side script (form.submit())
The situations where it doesn't work:
- clicking on a Favorite, History, or the recently-typed URLs list;
- clicking on 'Home' in IE's toolbar, or an item in IE's 'Links' toolbar;
- using location.href or location.replace() in client-side JScript/JavaScript/VBScript;
- using HierMenus (details);
- typing the URL directly in the browser and hitting Enter or clicking 'Go';
- launching a clickable URL from an e-mail or MS Office document;
- using Response.Redirect / Server.Transfer;
- using Response.AddHeader (302) or <meta http-equiv=refresh> to redirect;
- loading the URL with XML (see Article #2173);
- misspelling the variable name (many people assume HTTP_REFERRER).
Obviously, this variable cannot be relied upon for many situations.
Here is the code I used to test with. Ref.asp contains the following code:
<% Response.Write "Referer: " & Request.ServerVariables("HTTP_REFERER") %> |
And ref.htm contains the following:
<% Response.AddHeader "Refresh", "10;URL=ref.asp" ' interchanged with the <meta> version: %> <meta http-equiv='refresh' content='10;URL=ref.asp'> <form method=GET action=ref.asp name=getform> <input type=submit value=' Go there (GET) >> '> <input type=image style='cursor:hand'> </form><p> <form method=POST action=ref.asp name=postform> <input type=submit value=' Go there (POST) >> '> <input type=image style='cursor:hand'> </form><p> <a href='ref.asp'>Go there - straight link</a><p> <a href='#' onclick='window.location.href="ref.asp";return false;'>Go there - javascript href</a><p> <a href='#' onclick='window.location.replace("ref.asp");return false;'>Go there - javascript replace</a><p> <a href='#' onclick='document.getform.submit();return false;'>Go there - javascript GET</a><p> <a href='#' onclick='document.postform.submit();return false;'>Go there - javascript POST</a>
|
You'll notice that in Netscape 4, the referer is translated properly in all cases. With this exception, I think we're all glad, overall, that the number of users with Netscape 4 is quickly diminishing! :-)