Hrm...

You're right. That doesn't make any sense though. 

-----Original Message-----
From: Brad Wood [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 04, 2008 10:12 PM
To: CF-Talk
Subject: Re: Javascript in CFC

----- Original Message -----
From: "Andy Matthews" <[EMAIL PROTECTED]>


> That's irrelevant.
>
> The ColdFusion code would completely process before ANY JavaScript code
> would even make it to the browser.


Andy, I don't think you understand how cflocation works. Even though it is a

CF tag, the relocation does NOT happen on the server side.  If you make a 
test file and place the following code in it:

<script LANGUAGE="JavaScript" TYPE="text/JavaScript">
    alert('test');
</script>
<cflocation url="http://www.yahoo.com";>

..... and then hit that page, your browser will make two requests.  The first

request for your test page will come back looking much like this HTTP 
response:

=========================================
HTTP/1.1 302 Moved Temporarily
Date: Fri, 05 Sep 2008 03:04:33 GMT
Server: Apache/2.2.4 (Win32) JRun/4.0
location: http://www.yahoo.com
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Content-Length: 6551

<script LANGUAGE="JavaScript" TYPE="text/javascript">
    alert('test');
</script>
=========================================

Notice that the output of your page (the JavaScript) DOES get passed out to 
the browser.  However, your browser (Internet Explorer at least) will ignore

the body of the response and send out a second request for 
http://www.yahoo.com.

So whether or not the code is in a CFC or not, the browser is who actually 
does the redirect.  Of course, if one wants the JavaScript to execute BEFORE

the redirect, you want to send back a 200 response like so:

<script LANGUAGE="JavaScript" TYPE="text/JavaScript">
    alert('test');
    document.location.href = 'http://www.yahoo.com';
</script>

~Brad




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:312062
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to