Create a Link to the Previous Page Using ASP

With pages that are generated dynamically, you can’t provide a hardcoded link back to the previous page. However, ASP often provides you with the name of the page that contained the jump to the current page. With Request.ServerVariables(“HTTP_REFERER”) you can create the link on the fly. Keep in mind that you may not always get a value for the referrer page. Protect yourself by checking for an empty string before displaying the link text. This code shows one way of displaying the Back link if the information is available.

 <%@ Language=VBScript %><%if Request.ServerVariables("HTTP_REFERER") <>"" then%>">Back<%end if%>

Notice that the “REFERER” part of the parameter is misspelled. In fact, you must misspell it to make the function work.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: