3

Is there a way to redirect a user to a new window by using CFLocation? As far as I know you cannot use target=_blank in CFLocation. Is there another way to do it?

This is my code:

    <cfif cgi.PATH_INFO eq "/procedure-page.cfm">
       <cflocation url="http://www.example.com/example/example.cfm?id=XXXXXX&contactid=#returnStruct.contactID#&doctorid=#officeLocation#" addtoken="no" >
    <cfelse>
       <cflocation url="http://www.example.com/example/example.cfm?id=#example#&contactid=#returnStruct.contactID#&doctorid=#officeLocation#" addtoken="no" >
    </cfif>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Geo
  • 3,160
  • 6
  • 41
  • 82

3 Answers3

13

<cflocation> performs a client-side redirect, but it's initiated on the server side (it sends a request with a redirect in the header), so it can't know anything about "tabs" which are a browser thing. CF doesn't know anything about what's going on in the browser.

To do the sort of thing you want to do on the client site, you need to do the browser stuff with Javascript.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • 1
    I assume the OP meant open in a new window (not tab). Browsers can be set to open new windows in tabs. Regardless, I believe you are still correct and this cannot be handled by `CFLocation`. – Miguel-F Jan 15 '13 at 21:43
  • 3
    Window/tab it makes no difference: ColdFusion doesn't know anything about either of them. ColdFusion never has any interaction with the browser, it only communicates with the web server, which received HTTP requests from the browser, but even the web server doesn't know if the request came from or is intended for a tab / window / frame / whatever. All of that is managed by the browser. So one needs to do it with Javascript. This thread might be helpful: http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab. Either way, it's a JS question not a CF one. Sorry. – Adam Cameron Jan 15 '13 at 22:26
3

This is probably not the cleanest way, but it should work.

<cfoutput>
<cfif cgi.PATH_INFO eq "/procedure-page.cfm">
    <script type="text/javascript">
        window.open("http://www.example.com/example/example.cfm?id=XXXXXX&contactid=#returnStruct.contactID#&doctorid=#officeLocation#", '_blank');
    </script>
<cfelse>
    <script type="text/javascript">
        window.open("http://www.example.com/example/example.cfm?id=#example#&contactid=#returnStruct.contactID#&doctorid=#officeLocation#", '_blank');
    </script>
</cfif>
</cfoutput>
Billy
  • 236
  • 2
  • 5
0

I believe Adam is correct in that CFLocation cannot ask the browser to open in a new window (or tab). Something that might interest you however is the CFWindow tag. See the documentation here. Note that CFWindow does not open a new browser window either, but creates a <div> to simulate a popup window. Anyway, it has several options and I thought it might be worth you taking a look at. Maybe it can handle what you need.

Leigh
  • 28,765
  • 10
  • 55
  • 103
Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • Thanks for the reference. I already saw that but it won't work with what I am attempting to do. – Geo Jan 15 '13 at 21:53
  • Fyi, I modified the description to clarify how `cfwindow` actually operates. (Hopefully it is line with your original intent.) – Leigh Jan 15 '13 at 22:16
  • Thanks @Leigh, your comments/clarifications are always welcome. – Miguel-F Jan 16 '13 at 00:14