[thelist] An owed tip

David Shadovitz david_shadovitz at xontech.com
Tue Feb 19 11:34:01 CST 2002


I owe!  Sorry for the length of this one.

<tip type="ColdFusion" author="David Shadovitz">

Sometimes the Netscape browser reacts to a CFLOCATION by displaying a
page which says "The document has moved here", where the word "here" is
a hyperlink to the correct page.

In my experience, the problem occurs when there is HTML code along with
the CFLOCATION.  This is generally due to bad coding and can be
avoided.  (Or you can keep your bad code and use a META refresh tag
instead of CFLOCATION.)

As an example, consider a page which either (a) displays records or (b)
deletes a record and then displays the remaining records.  A flag is
passed in to govern whether action (a) or (b) should be performed.

Here's a BAD way to code it.  It's bad because when the action is
"delete", the html, head and body tags appear along with the CFLOCATION
tag.

<html>
  <head></head>
  <body>

    <cfswitch expression="#action#">

      <cfcase value="delete">
        delete from myTable where...
        <cflocation url="#CGI.SCRIPT_NAME#?action=display">
      </cfcase>

      <cfcase value="display">
        HTML table goes here
    </cfcase>

  </body>
</html>

Here's a GOOD way to code it.  The html, head and body tags are only
written by the server when the action is "display".  When the action is
"delete", the CFLOCATION tag is all alone on the page and Netscape
behaves well.

<cfswitch expression="#action#">

  <cfcase value="delete">
    <cfquery>delete from myTable where...</cfquery>
    <cflocation url="#CGI.SCRIPT_NAME#?action=display">
  </cfcase>

  <cfcase value="display">
    <html>
    <head></head>
    <body>
      HTML table goes here
    </body>
    </html>
  </cfcase>

</cfswitch>

Another way to look at this is: don't mix purely server-side code with
display code.  (By "purely server-side code" I mean things such as
queries, not code to do things such as alternating the background color
of a row in an HTML table.)

</tip>




More information about the thelist mailing list