Link to home
Start Free TrialLog in
Avatar of skibama1
skibama1

asked on

CFLocation and javascript

Can you set the url paramter of the cflocation tag to be a javascript command?  I am not having any luck.

What I have done is created a page that queries for emails, then set the url in cflocation to equal "mailto:#queryoutput#".  It works great but leaves a blank IE window open every time the link is clicked which is s pain:

<cfif not isdefined("URL.group")>
      <p>Sorry, no groups were selected.</p>
      <cfabort>
<cfelse>
      <cfquery name="get_data" datasource="email_groups">
      SELECT * FROM main_data
      WHERE #URL.group# = 1
      </cfquery>

      <cfset catch_var = "">
      <cfloop query="get_data">
            <cfset catch_var = Insert(#get_data.email_add#, #catch_var#, 0)>
            <cfset catch_var = Insert(";", #catch_var#, 0)>
      </cfloop>
      <cfset catch_var = RemoveChars(#catch_var#, 1, 1)>
      <cfset catch_var = Insert("mailto:", #catch_var#, 0)>
      <cflocation url="#catch_var#">
      <cflocation url="javascript:window.close()">
</cfif>
Avatar of black0ps
black0ps
Flag of United States of America image

You can't have two cflocations right after each other. Doesn't work.

If you want the window to close, try something like:

<cflocation url="close.cfm">

close.cfm:
<body onLoad="javascript:window.close();">
</body>

However, what are you trying to do with the code. I'm not sure the <cflocation url="mailto:some@email.com"> is going to accomplish what you want it to do.
Avatar of skibama1
skibama1

ASKER

I know the mail part works but when the link is called it leaves an open IE window with nothing in it.  My users are complaining that they love being able to click on the groups and send email but they HATE the windows that are left open.
BlackOps is right. And he has a good question: what is it that you want to do?

I have 2 guesses but both dont really seem right.
1) Maybe you want to setup a link to send the emails in which case you would want to use <a href="#cathc_var#">Email Group</a>.
2) Maybe you want to send an email yourself, in which case you might want to use <cfmail>.

Also, the javascript command for url changing is 'document.location="<come URL>"'.

HTH

Steven
Black0ps is right and so is everyone else that is going to tell you you can't do that.

The reason the window is left open is 2 fold.

1) You should not have javascript inside the cflocation

2) When the 1st cflocation is executed the window the second one won't be.

Personally I would not do what you are doing anyway because the mailto  is limited.

Why not have a form that sends the email and then sends them back to where they want to go?


But if the mail part is doing what you want for now then I recommend that you instead of doing a cflocation to a mail do a cflocation to a page that has the email link and onclick of the link it closes the window.
What I suggest is instead of doing the processing on the next page with the link, do the processing on the page that has the links the user's can click on.

    <cfquery name="get_data" datasource="email_groups">
     SELECT * FROM main_data
     WHERE #URL.group# = 1
     </cfquery>

     <cfset catch_var = "">
     <cfloop query="get_data">
          <cfset catch_var = Insert(#get_data.email_add#, #catch_var#, 0)>
          <cfset catch_var = Insert(";", #catch_var#, 0)>
     </cfloop>
     <cfset catch_var = RemoveChars(#catch_var#, 1, 1)>
     <cfset catch_var = Insert("mailto:", #catch_var#, 0)>

<!--- Output link --->
<cfoutput><a href="#catch_var#">Group Number 1</a></cfoutput>    

*break*
To: smaglio81 & mrichmon:
Thanks for the validation. Sometimes I wonder if i'm not talking out of my butt.
OK, I see what everyone is saying.  But let me explain what I am doing and then you may be able to help me more.  I work at a school with a VERY lazy IT group.  Email groups on the exchange server is very low on their priority list....so low that I'm not even sure it makes the list.  Just as with most other organizations we have lots of people (150+ staff members) and Lots of groups - probably on the order of 75 groups.  Well the IT won't give me access to go in and create the groups on my own....go figure.

So to get around it I created a database with all of our employees matched up with all the possible email groups.  I have a page that has all the groups as a link.  The "email group" links on this page (regular http links) calls another page (code above) with a URL variable telling the query which group to find.  It then builds a mailto link and calls that from the cflocation.

So far I am leaning towards blackOps last suggestion, but I don't like the fact that the "menu" window would not stay open.  Alot of users have the page set up directly in Outlook (as a folder homepage) and I suspect this would cause problems.  What I would really like to see is when the user clicks on the menu page the only thing that remains open is the new email. If this is called through another window I would like for that window to close on it's own. Since the window would be a child it shouldn't be too hard to close it with some sort of javascript.
I forgot to say that cfmail is out of the question because of firewall reasons.  It actually would have been my choice but with the firewall it was kaput.
ASKER CERTIFIED SOLUTION
Avatar of black0ps
black0ps
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That might work.  I'll try it this weekend sometime.  Wish i could get past that firewall....
To get past the firewall, have you tried using the same outgoing mail in the cfmail tag as the exchange server uses? I mean, mail has to get out somehow doesn't it?
Just leave out the window.close() in the javascript if you don't want the main window to open. When you use window.open('mailto:whoever'); it opens up an email page and not a new window.
I tried using doing that do get past the firewall but because they won't let the server be part of the domain I could not get a connection.  They are incredible paranoid.
Worked like a charm!  Thanks!