Browser Redirection
At
times, you may wish to redirect a user’s browser to a location
other than the current template. This is generally handled using the
CFLOCATION
tag. The following example creates a
drop-down box listing several web sites. Choosing one of the sites
and clicking on the Go button posts the form to itself and uses the
CFLOCATION
tag to redirect the user to the
selected web site.
<CFIF IsDefined('Form.Go')> <CFLOCATION URL="http://#Goto#" ADDTOKEN="No"> </CFIF> <B>Please choose a location:</B><BR> <FORM ACTION="Go.cfm" METHOD="post"> <SELECT NAME="Goto"> <OPTION VALUE="www.allaire.com" Selected>Allaire</OPTION> <OPTION VALUE="www.yahoo.com">Yahoo</OPTION> <OPTION VALUE="www.amkor.com">Amkor</OPTION> </SELECT> <INPUT TYPE="Submit" NAME="Go" VALUE="Go"></FONT></TD></FORM>
The URL
attribute specifies an absolute or relative path to the page you want
to redirect the user’s browser to. ADDTOKEN
is an optional attribute and indicates whether to append client
variable information (CFID
and
CFToken
values) to the end of the URL specified in
the URL
attribute. In order to use the
ADDTOKEN
attribute,
CLIENTMANAGEMENT
must be turned on in the
Application.cfm
file. The default value for
ADDTOKEN
is Yes
.
Due to the way
ColdFusion assembles dynamic pages, you shouldn’t attempt to
use the CFLOCATION
tag within a template after a
cookie variable has been set. Setting a cookie variable and using
CFLOCATION
afterward results in the cookie not being set. If you need to redirect ...
Get Programming ColdFusion now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.