View comments | RSS feed

cflocation

Description

Stops page execution and opens a ColdFusion page or HTML file.

Category

Flow-control tags, Page processing tags

Syntax

<cflocation
  url = "url"
  addToken = "Yes" or "No">

See also

cfabort, cfbreak, cfexecute, cfexit, cfif, cfloop, cfswitch, cfthrow, cftry

Attributes

Attribute Req/Opt Default Description
url
Required

URL of HTML file or CFML page to open.
addToken
Optional

clientManagement must be enabled (see cfapplication).
  • Yes: appends client variable information to URL
  • No

Usage

You might write a standard message or response in a file, and call it from several applications. You could use this tag to redirect the user's browser to the standard file.

If you use this tag after the cfflush tag on a page, an error is thrown.

Warning:   Do not set a cookie variable on a page on which you use this tag. If you do, the cookie is not saved on the browser. Similarly, if you use a cookie to store a client variable, the client variable is not set.

Example

<!--- This view-only example shows the use of cflocation --->
<h3>cflocation Example</h3>
<p>This tag redirects the browser to a web resource; normally, you would 
use this tag to go to a CF page or an HTML file on the same server. 
The addToken attribute lets you send client information to the 
target page.
<p>This code redirects you to CFDOCS home page (if you remove the comment 
marks, this information displays in frame):
<!--- <cflocation url = "../cfdocs/index.htm" addToken = "No"> --->

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


sgilson102 said on Aug 12, 2002 at 9:28 PM :
Macromedia Update:

The documentation incorrectly states that setting cookie on the same page you use cflocation would result in the cookie not being set. The cookie will be set correctly.

Stephen M. Gilson
Macromedia
Wolfverine said on Jan 16, 2003 at 11:10 AM :
cflocation do NOT works inside a percistent Component.

Those lines are in the comoponent :
<cftrace text="cflocation => '#LogonURL#&#ErrorURLParam#=#URLEncodedFormat(_ErrorMsg)#&#RedirectURLParam#=#URLEncodedFormat(tmp_UUID)#'" type="information">
<cflocation url="#LogonURL#&#ErrorURLParam#=#URLEncodedFormat(_ErrorMsg)#&#RedirectURLParam#=#URLEncodedFormat(tmp_UUID)#" addToken="NO">

I've got in debug :
[16:56:37.037 L:\ColdFusion\Custom Component\CC_Users.cfc @ line: 521] [9012 ms (10 ms)] -
cflocation => '/BO/Logon.cfm?FuseAction=ACL_USERS.Logon&Error_Msg=Votre%20session%20a%20expir%E9e&RedirectUrl=UC7B4C17D50DADE7F45381DE669C32468'
But I'm NOT redirected to the /Bo/logon page.
If Comoponent is not percistent (Loaded at each page process) it's works !
byteback said on Jun 30, 2003 at 5:41 PM :
How come cflocation still work within HTML comment like this <!-- <cflocation url = "../cfdocs/index.htm" addToken = "No"> -->? Is there any official documentation on this? Are there any other CFML tags that still work within the HTML comment like this?
hlichtin said on Jul 1, 2003 at 4:01 PM :
HTML comment tags do not affect ColdFusion processing, they only prevent display of the resulting HTML output in the browser. The cflocation tag generates an HTTP status 302 redirection message with the new URL. Because the redirect is an HTTP message, not HTML, the comment tag does not have any effect, and the redirection happens.
webucator said on Jul 23, 2003 at 1:34 PM :
Using CFLOCATION after CFFLUSH does not cause an error to be thrown, it just prevents CFLOCATION from executing.
philklein said on Jan 24, 2004 at 9:25 AM :
can i use a CreateTimeSpan(days, hours, minutes, seconds)
operation some other method to delay a <cflocation redirect? I can use http:// refresh because this redirect will occur after the header of a page has been written.
cousett said on Dec 11, 2004 at 11:18 AM :
I also want to know if there is some way to create a delay with the cflocation tag or using anohter tag. I want the user to see the page for about 30 seconds but then relocate to another page.

Thanks for your help.
No screen name said on Nov 4, 2006 at 10:43 AM :
To my knowledge the only two ways to create a delay are to use Java or Javascript. If you use Javascript you won't be able to use <CFLOCATION>.
To use Java just create a java.Threading object and use sleep(x). Keep in mind that X is in milliseconds so if you want 5 seconds you put in 5000.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt166.htm