Redirecting the user’s browser using the CFLOCATION tag in ColdFusion

Readability

Redirecting the user's browser using the CFLOCATION tag in ColdFusion

The fol­low­ing exam­ple shows how you can redi­rect the user’s browser in Cold­Fu­sion using the <CFLO­CA­TION> tag.


Note that a <CFLO­CA­TION> tag redi­rects the user’s browser imme­di­ately. If you want to redi­rect the user’s browser after a slight delay you can use the HTML <meta> tag, as seen in the fol­low­ing exam­ple (which redi­rects the user to google​.com after a 5 sec­ond delay):



    



    

You will be redirected to google.com after 5 seconds.

Or, you could do a JavaScript redi­rec­tion by set­ting the document.location prop­erty, as seen in the fol­low­ing example:



    



    

You will be redirected to google.com after 5 seconds.

The following example shows how you can redirect the user’s browser in ColdFusion using the <CFLOCATION> tag.

<cflocation url="http://google.com/" />

Note that a <CFLOCATION> tag redirects the user’s browser immediately. If you want to redirect the user’s browser after a slight delay you can use the HTML <meta> tag, as seen in the following example (which redirects the user to google.com after a 5 second delay):

<html>
<head>
    <meta http-equiv="Refresh" content="5; URL=http://google.com/">
</head>
<body>
 
    <h1>You will be redirected to <a href="http://google.com/">google.com</a> after 5 seconds.</h1>
 
</body>
</html>

Or, you could do a JavaScript redirection by setting the document.location property, as seen in the following example:

<html>
<head>
    <script type="text/javascript">
        function init() {
            setTimeout("jsRedirect('http://google.com/')", 5000)
        }
 
        function jsRedirect(url) {
            document.location = url;
        }
    </script>
</head>
<body onload="init();"">
 
    <h1>You will be redirected to <a href="http://google.com/">google.com</a> after 5 seconds.</h1>
 
</body>
</html>

Leave a Reply

Your email address will not be published.