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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access