Skip to Main Content
Programming ColdFusion MX, 2nd Edition
book

Programming ColdFusion MX, 2nd Edition

by Rob Brooks-Bilson
August 2003
Intermediate to advanced content levelIntermediate to advanced
1140 pages
68h 45m
English
O'Reilly Media, Inc.
Content preview from Programming ColdFusion MX, 2nd Edition

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 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://#form.Goto#" addtoken="No"> 
</cfif>
   
<h2>Please choose a location:</h2>
<cfoutput>
<form action="#CGI.Script_Name#" method="Post">
</cfoutput>
  <select name="Goto">
    <option value="www.macromedia.com" Selected>Macromedia</option>
    <option value="www.yahoo.com">Yahoo</option>
    <option value="www.amkor.com">Amkor</option>
  </select>
<input type="Submit" name="Go" value="Go">
</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.

You can also redirect to a different page using the cfheader tag:

<cfheader name="Refresh" value="0; URL=http://www.example.com/mytemplate.cfm">

This code uses the cfheader tag to generate a custom HTTP header with a Refresh element that contains ...

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.
Start your free trial

You might also like

Programming ColdFusion

Programming ColdFusion

Rob Brooks-Bilson

Publisher Resources

ISBN: 0596003803Supplemental ContentErrata Page